我正在尝试从Google地理编码API获取完整的jSON响应,以便可以测试结果“状态”。

从文档中:


  responsePath:应用于HTTP正文的可选JSONPath。看到
  https://github.com/s3u/JSONPath表示JSON路径的语法。


所以我使用了“ responsePath”:“ $ .. *”,但是它使响应变得混乱了。

例:

        [
           [
              {
                 "address_components":[
                    {
                       "long_name":"Caracas",
                       "short_name":"CCS",
                       "types":[
                          "locality",
                          "political"
                       ]
                    },
                    {
                       "long_name":"Libertador",
                       "short_name":"Libertador",
                       "types":[
                          "administrative_area_level_2",
                          "political"
                       ]
                    },
                    {
                       "long_name":"Capital District",
                       "short_name":"Dto. Capital",
                       "types":[
                          "administrative_area_level_1",
                          "political"
                       ]
                    },
                    {
                       "long_name":"Venezuela",
                       "short_name":"VE",
                       "types":[
                          "country",
                          "political"
                       ]
                    }
                 ],
                 "formatted_address":"Caracas, Venezuela",
                 "geometry":{
                    "bounds":{
                       "northeast":{
                          "lat":10.5401335,
                          "lng":-66.7179533
                       },
                       "southwest":{
                          "lat":10.39665,
                          "lng":-67.0627784
                       }
                    },
                    "location":{
                       "lat":10.4696404,
                       "lng":-66.8037185
                    },
                    "location_type":"APPROXIMATE",
                    "viewport":{
                       "northeast":{
                          "lat":10.5401335,
                          "lng":-66.7179533
                       },
                       "southwest":{
                          "lat":10.39665,
                          "lng":-67.0627784
                       }
                    }
                 },
                 "place_id":"ChIJB0iCza1YKowRg4SZCq4u3ZM",
                 "types":[
                    "locality",
                    "political"
                 ]
              },
              {
                 "address_components":[
                    {
                       "long_name":"Venezuela",
                       "short_name":"VE",
                       "types":[
                          "country",
                          "political"
                       ]
                    }
                 ],
                 "formatted_address":"Venezuela",
                 "geometry":{
                    "bounds":{
                       "northeast":{
                          "lat":12.4866941,
                          "lng":-59.805666
                       },
                       "southwest":{
                          "lat":0.647529,
                          "lng":-73.351558
                       }
                    },
                    "location":{
                       "lat":6.42375,
                       "lng":-66.58973
                    },
                    "location_type":"APPROXIMATE",
                    "viewport":{
                       "northeast":{
                          "lat":14.470409,
                          "lng":-59.80378
                       },
                       "southwest":{
                          "lat":-4.1438179,
                          "lng":-79.0255611
                       }
                    }
                 },
                 "place_id":"ChIJAdjLNstTKIwR003VfFjyoNw",
                 "types":[
                    "country",
                    "political"
                 ]
              }
           ],
           "OK",
           {
              "address_components":[
                 {
                    "long_name":"Caracas",
                    "short_name":"CCS",
                    "types":[
                       "locality",
                       "political"
                    ]
                 },
                 {
                    "long_name":"Libertador",
                    "short_name":"Libertador",
                    "types":[
                       "administrative_area_level_2",
                       "political"
                    ]
                 },
                 {
                    "long_name":"Capital District",
                    "short_name":"Dto. Capital",
                    "types":[
                       "administrative_area_level_1",
                       "political"
                    ]
                 },
                 {
                    "long_name":"Venezuela",
                    "short_name":"VE",
                    "types":[
                       "country",
                       "political"
                    ]
                 }
              ],
              "formatted_address":"Caracas, Venezuela",
              "geometry":{
                 "bounds":{
                    "northeast":{
                       "lat":10.5401335,
                       "lng":-66.7179533
                    },
                    "southwest":{
                       "lat":10.39665,
                       "lng":-67.0627784
                    }
                 },
                 "location":{
                    "lat":10.4696404,
                    "lng":-66.8037185
                 },
                 "location_type":"APPROXIMATE",
                 "viewport":{
                    "northeast":{
                       "lat":10.5401335,
                       "lng":-66.7179533
                    },
                    "southwest":{
                       "lat":10.39665,
                       "lng":-67.0627784
                    }
                 }
              },
              "place_id":"ChIJB0iCza1YKowRg4SZCq4u3ZM",
              "types":[
                 "locality",
                 "political"
              ]
           },
           {
              "address_components":[
                 {
                    "long_name":"Venezuela",
                    "short_name":"VE",
                    "types":[
                       "country",
                       "political"
                    ]
                 }
              ],
              "formatted_address":"Venezuela",
              "geometry":{
                 "bounds":{
                    "northeast":{
                       "lat":12.4866941,
                       "lng":-59.805666
                    },
                    "southwest":{
                       "lat":0.647529,
                       "lng":-73.351558
                    }
                 },
                 "location":{
                    "lat":6.42375,
                    "lng":-66.58973
                 },
                 "location_type":"APPROXIMATE",
                 "viewport":{
                    "northeast":{
                       "lat":14.470409,
                       "lng":-59.80378
                    },
                    "southwest":{
                       "lat":-4.1438179,
                       "lng":-79.0255611
                    }
                 }
              },
              "place_id":"ChIJAdjLNstTKIwR003VfFjyoNw",
              "types":[
                 "country",
                 "political"
              ]
           },
           [
              {
                 "long_name":"Caracas",
                 "short_name":"CCS",
                 "types":[
                    "locality",
                    "political"
                 ]
              },
              {
                 "long_name":"Libertador",
                 "short_name":"Libertador",
                 "types":[
                    "administrative_area_level_2",
                    "political"
                 ]
              },
              {
                 "long_name":"Capital District",
                 "short_name":"Dto. Capital",
                 "types":[
                    "administrative_area_level_1",
                    "political"
                 ]
              },
              {
                 "long_name":"Venezuela",
                 "short_name":"VE",
                 "types":[
                    "country",
                    "political"
                 ]
              }
           ],
           "Caracas, Venezuela",
           {
              "bounds":{
                 "northeast":{
                    "lat":10.5401335,
                    "lng":-66.7179533
                 },
                 "southwest":{
                    "lat":10.39665,
                    "lng":-67.0627784
                 }
              },
              "location":{
                 "lat":10.4696404,
                 "lng":-66.8037185
              },
              "location_type":"APPROXIMATE",
              "viewport":{
                 "northeast":{
                    "lat":10.5401335,
                    "lng":-66.7179533
                 },
                 "southwest":{
                    "lat":10.39665,
                    "lng":-67.0627784
                 }
              }
           },
           "ChIJB0iCza1YKowRg4SZCq4u3ZM",
           [
              "locality",
              "political"
           ],
           {
              "long_name":"Caracas",
              "short_name":"CCS",
              "types":[
                 "locality",
                 "political"
              ]
           },
           {
              "long_name":"Libertador",
              "short_name":"Libertador",
              "types":[
                 "administrative_area_level_2",
                 "political"
              ]
           },
           {
              "long_name":"Capital District",
              "short_name":"Dto. Capital",
              "types":[
                 "administrative_area_level_1",
                 "political"
              ]
           },
           {
              "long_name":"Venezuela",
              "short_name":"VE",
              "types":[
                 "country",
                 "political"
              ]
           },
           "Caracas",
           "CCS",
           [
              "locality",
              "political"
           ],
           "locality",
           "political",
           "Libertador",
           "Libertador",
           [
              "administrative_area_level_2",
              "political"
           ],
           "administrative_area_level_2",
           "political",
           "Capital District",
           "Dto. Capital",
           [
              "administrative_area_level_1",
              "political"
           ],
           "administrative_area_level_1",
           "political",
           "Venezuela",
           "VE",
           [
              "country",
              "political"
           ],
           "country",
           "political",
           {
              "northeast":{
                 "lat":10.5401335,
                 "lng":-66.7179533
              },
              "southwest":{
                 "lat":10.39665,
                 "lng":-67.0627784
              }
           },
           {
              "lat":10.4696404,
              "lng":-66.8037185
           },
           "APPROXIMATE",
           {
              "northeast":{
                 "lat":10.5401335,
                 "lng":-66.7179533
              },
              "southwest":{
                 "lat":10.39665,
                 "lng":-67.0627784
              }
           },
           {
              "lat":10.5401335,
              "lng":-66.7179533
           },
           {
              "lat":10.39665,
              "lng":-67.0627784
           },
           10.5401335,
           -66.7179533,
           10.39665,
           -67.0627784,
           10.4696404,
           -66.8037185,
           {
              "lat":10.5401335,
              "lng":-66.7179533
           },
           {
              "lat":10.39665,
              "lng":-67.0627784
           },
           10.5401335,
           -66.7179533,
           10.39665,
           -67.0627784,
           "locality",
           "political",
           [
              {
                 "long_name":"Venezuela",
                 "short_name":"VE",
                 "types":[
                    "country",
                    "political"
                 ]
              }
           ],
           "Venezuela",
           {
              "bounds":{
                 "northeast":{
                    "lat":12.4866941,
                    "lng":-59.805666
                 },
                 "southwest":{
                    "lat":0.647529,
                    "lng":-73.351558
                 }
              },
              "location":{
                 "lat":6.42375,
                 "lng":-66.58973
              },
              "location_type":"APPROXIMATE",
              "viewport":{
                 "northeast":{
                    "lat":14.470409,
                    "lng":-59.80378
                 },
                 "southwest":{
                    "lat":-4.1438179,
                    "lng":-79.0255611
                 }
              }
           },
           "ChIJAdjLNstTKIwR003VfFjyoNw",
           [
              "country",
              "political"
           ],
           {
              "long_name":"Venezuela",
              "short_name":"VE",
              "types":[
                 "country",
                 "political"
              ]
           },
           "Venezuela",
           "VE",
           [
              "country",
              "political"
           ],
           "country",
           "political",
           {
              "northeast":{
                 "lat":12.4866941,
                 "lng":-59.805666
              },
              "southwest":{
                 "lat":0.647529,
                 "lng":-73.351558
              }
           },
           {
              "lat":6.42375,
              "lng":-66.58973
           },
           "APPROXIMATE",
           {
              "northeast":{
                 "lat":14.470409,
                 "lng":-59.80378
              },
              "southwest":{
                 "lat":-4.1438179,
                 "lng":-79.0255611
              }
           },
           {
              "lat":12.4866941,
              "lng":-59.805666
           },
           {
              "lat":0.647529,
              "lng":-73.351558
           },
           12.4866941,
           -59.805666,
           0.647529,
           -73.351558,
           6.42375,
           -66.58973,
           {
              "lat":14.470409,
              "lng":-59.80378
           },
           {
              "lat":-4.1438179,
              "lng":-79.0255611
           },
           14.470409,
           -59.80378,
           -4.1438179,
           -79.0255611,
           "country",
           "political"
        ]

最佳答案

好吧,看来现在很清楚。 “ Messed up”响应是应用JSONPath表达式的结果,其结果是数组,而不是JSON Object。您可以在此处查看一些示例:https://github.com/s3u/JSONPath/blob/master/test/test.examples.js

因此,如果只需要状态,则可以使用以下过滤器:"responsePath": "$.status"。否则,您可以完全删除responsePath并获取原始的JSON对象。

07-24 09:51