码迷,mamicode.com
首页 > 编程语言 > 详细

四、使用jsonpath提取复杂响应中的数组及其他字段

时间:2019-12-04 20:26:49      阅读:427      评论:0      收藏:0      [点我收藏+]

标签:array   图片   复杂   list   priority   消费   字符串   nbsp   pat   

一、jsonpath实时调试url

http://jsonpath.com/

技术图片

 

 

 二、对于复杂响应的提取字段

    1.json字符串如下:

  

{
    "code": 0,
    "data": {
        "loanArray": [{
                "name": "测试测试",
                "priority": 0,
                "list": [{
                        "period": "24期",
                        "id": 66601
                    },
                    {
                        "period": "36期",
                        "id": 2792
                    }
                ]
            },
            {
                "name": "测试业测试",
                "priority": 1,
                "list": [{
                        "period": "24期",
                        "id": 66637
                    },
                    {
                        "period": "36期",
                        "id": 66633
                    }
                ]
            },
            {
                "name": "测试薪测试",
                "priority": 2,
                "list": [{
                        "period": "24期",
                        "id": 66646
                    },
                    {
                        "period": "36期",
                        "id": 66642
                    }
                ]
            },
            {
                "name": "测试享测试",
                "priority": 3,
                "list": [{
                        "period": "24期",
                        "id": 66655
                    },
                    {
                        "period": "36期",
                        "id": 66651
                    }
                ]
            },
            {
                "name": "我才测试",
                "priority": 4,
                "list": [{
                        "period": "24期",
                        "id": 666666
                    },
                    {
                        "period": "36期",
                        "id": 66622
                    }
                ]
            },
            {
                "name": "我房测试",
                "priority": 5,
                "list": [{
                        "period": "24期",
                        "id": 66619
                    },
                    {
                        "period": "36期",
                        "id": 66615
                    }
                ]
            },
            {
                "name": "我保测试",
                "priority": 6,
                "list": [{
                        "period": "24期",
                        "id": 66611
                    },
                    {
                        "period": "36期",
                        "id": 66607
                    }
                ]
            }
        ],
        "loanP": [{
                "id": 2,
                "keys": "CASH_FLOW",
                "name": "资金周转"
            },
            {
                "id": 6,
                "keys": "ASSET",
                "name": "购买货物/原材/设备"
            },
            {
                "id": 14,
                "keys": "ENALRGE",
                "name": "扩大生产/经营"
            },
            {
                "id": 15,
                "keys": "DECORATION",
                "name": "装修"
            },
            {
                "id": 16,
                "keys": "EDUCATION",
                "name": "教育支出"
            },
            {
                "id": 17,
                "keys": "MEDICAL",
                "name": "医疗"
            },
            {
                "id": 18,
                "keys": "WAGE",
                "name": "支付员工工资"
            },
            {
                "id": 19,
                "keys": "CONSUME",
                "name": "日常生活消费"
            },
            {
                "id": 20,
                "keys": "BUY_CAR",
                "name": "增购新车"
            }
        ]
    },
    "mask": "c1b8333a-732c-4666f-adad-b68b0b275f65",
    "msg": "success",
    "timestamp": 1575452653
}

取出loanArray数组下name="测试薪测试"的list下的id

方法如下:$..loanArray[?(@.name="测试薪测试")].list[0].id

技术图片

 

 

四、使用jsonpath提取复杂响应中的数组及其他字段

标签:array   图片   复杂   list   priority   消费   字符串   nbsp   pat   

原文地址:https://www.cnblogs.com/chushujin/p/11984796.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!