添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account "code": "0", "message": "查询用户成功", "bodyMessage": "[{"Uid":20162880,"UserName":"XT3035985","NickName":"🤥😝😛😛","Email":"","PhoneNumber":"133****7779","UserHead":"https://test.bits71.com//Secrecy/private/2018/3/20/2018034_80.jpg","BSCode":105487,"Signature":"Ffdddrfddgfddfdddddd4555@55444","Sex":0,"Country":"6541","Province":"8358","City":"8359","Location":"中国","Accid":"m2016288"}]", "pageIndex": 0, "pageSize": 0, "total": 0, "SubCode": "0"

提取code\message 正常的数据结构可以成功。

- eq: ["body.code","0"]
 - eq: ["body.message","查询用户成功"]

问题为:提取bodyMessage的value中的Uid时,由于数据结构为数组嵌套字典格式,使用.方法提取时,就不能使用了.

- eq: ["body.bodyMessage.0.Uid",20162880]

@searchbb 感谢反馈,后续我考虑兼容支持下。

可以考虑在validate生成的时候就自动按照jmespath的格式来生成所有的eq吧?附一个我之前写的方法,代码应该还有很大优化空间,仅供参考:

# 遍历字典/列表,以层级深度为1的目标,获取到所有的key/value对
    def get_all_items(self, item, prefix='', mode=1):
        :param item: 一个字典或列表,无论深度如何
        :param prefix: key的前缀,默认为空,递归时会用到
        :param mode: 输出模式,1-value为纯扁平模式,0-各级value均保存
        :return: 字典,深度为1的key/value对
        my_items = {}
        if isinstance(item, dict):
            if len(item) == 0:
                my_items[prefix] = {}
            for x in range(len(item)):
                t_key = item.keys()[x]
                t_val = item[t_key]
                if prefix != '':
                    t_key = str(prefix) + "." + str(t_key)
                else:
                if not (mode and isinstance(t_val, (dict, list, tuple, set))):
                    my_items[t_key] = t_val
                my_items = dict(my_items.items() + self.get_all_items(item=t_val, prefix=t_key).items())
        elif isinstance(item, (list, set, tuple)):
            if len(item) == 0:
                my_items[prefix] = []
            for x in range(len(item)):
                if prefix != '':
                    t_key = "%s[%d]" % (prefix, x)
                else:
                    t_key = "[%d]" % x
                if not (mode and isinstance(item[x], (dict, list, tuple, set))):
                    my_items[t_key] = item[x]
                my_items = dict(my_items.items() + self.get_all_items(item=item[x], prefix=t_key).items())
        else:  # the end level
            if prefix == '':
                my_items[item] = ''
        return my_items