0

我有这个 Bing Maps JSON 文件,我想从里面检索“++formattedAddress++”

{
    "statusCode": 200,
    "statusDescription": "OK",
    "copyright": "Copyright © 2013 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.",
    "authenticationResultCode": "ValidCredentials",
    "resourceSets": [
        {
            "resources": [
                {
                    "__type": "Location:http://schemas.microsoft.com/search/local/ws/rest/v1",
                    "point": {
                        "type": "Point",
                        "coordinates": [
                            63.8185213804245,
                            12.105498909950256
                        ]
                    },
                    "matchCodes": [
                        "Good"
                    ],
                    "address": {
                        "addressLine": "55 Stuff",
                        "locality": "Stuff",
                        "++formattedAddress++": "55 Stuff, 51512 Stuff",
                        "postalCode": "25521",
                        "adminDistrict2": "Stuff-Stuff",
                        "countryRegion": "UK",
                        "adminDistrict": "NL"
                    },
                    "bbox": [
                        84.81465866285382,
                        12.097347537264563,
                        50.822384097995176,
                        7.11365028263595
                    ],
                    "name": "55 Stuff, 51122 Stuff",
                    "confidence": "Medium",
                    "entityType": "Address",
                    "geocodePoints": [
                        {
                            "calculationMethod": "Interpolation",
                            "type": "Point",
                            "usageTypes": [
                                "Display",
                                "Route"
                            ],
                            "coordinates": [
                                50.8185213804245,
                                7.105498909950256
                            ]
                        }
                    ]
                }
            ],
            "estimatedTotal": 1
        }
    ],
    "traceId": "8a13f73cab93472db1253e4c1621c651|BL2M002306|02.00.83.1900|BL2MSNVM001274, BL2MSNVM003152",
    "brandLogoUri": "http://dev.virtualearth.net/Branding/logo_powered_by.png"
}

到目前为止我尝试过的是这样的:

final JSONArray jsonMainArr = locationData.getJSONArray("resourceSets").getJSONObject(0).getJSONArray("resources");
final JSONObject childJSONObject = jsonMainArr.getJSONObject(0);
return childJSONObject.getString("formattedAddress");

childJSONObject 仍然比 formattedAddress 高 2-3 级,查询变得非常低效

4

2 回答 2

3

从当前 json String 获取 formattedAddress 地址值:

final JSONObject childJSONObject = jsonMainArr.getJSONObject(0)
                                                .getJSONObject("address");
return childJSONObject.getString("++formattedAddress++");
于 2013-01-14T12:44:33.303 回答
0

有很多在线站点,您可以在其中粘贴复杂的代码并以简单的方式获取它。例如http://json.parser.online.fr/

于 2013-01-14T12:51:26.253 回答