简体   繁体   English

Bing Maps JSON无法使用JSON.parse进行解析

[英]Bing Maps JSON not parsing with JSON.parse

I'm trying to use Bing Maps for reverse geocoding purposes in a Windows Store Application. 我正在尝试使用Bing Maps在Windows Store应用程序中进行反向地理编码。 My request (using WinJS.xhr) goes through just fine, and I get a response similar to this one from their example page: 我的请求(使用WinJS.xhr)顺利进行,并且从他们的示例页面中得到了与此响应类似的响应:

{
   "authenticationResultCode":"ValidCredentials",
   "brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png",
   "copyright":"Copyright © 2011 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.",
   "resourceSets":[
      {
         "estimatedTotal":1,
         "resources":[
            {
               "__type":"Location:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1",
               "bbox":[
                  47.636705672917948,
                  -122.137016420622,
                  47.6444311080593,
                  -122.1217297861384
               ],
               "name":"1 Microsoft Way, Redmond, WA 98052",
               "point":{
                  "type":"Point",
                  "coordinates":[
                     47.640568390488625,
                     -122.1293731033802
                  ]
               },
               "address":{
                  "addressLine":"1 Microsoft Way",
                  "adminDistrict":"WA",
                  "adminDistrict2":"King Co.",
                  "countryRegion":"United States",
                  "formattedAddress":"1 Microsoft Way, Redmond, WA 98052",
                  "locality":"Redmond",
                  "postalCode":"98052"
               },
               "confidence":"Medium",
               "entityType":"Address",
               "geocodePoints":[
                  {
                     "type":"Point",
                     "coordinates":[
                        47.640568390488625,
                        -122.1293731033802
                     ],
                     "calculationMethod":"Interpolation",
                     "usageTypes":[
                        "Display",
                        "Route"
                     ]
                  }
               ],
               "matchCodes":[
                  "Good"
               ]
            }
         ]
      }
   ],
   "statusCode":200,
   "statusDescription":"OK",
   "traceId":"99b1256e09044490bce82bbbba1dab7a"
}

However when I call JSON.parse on the data and try to display it, all it returns is 但是,当我在数据上调用JSON.parse并尝试显示它时,它返回的只是

[object Object]

What am I doing wrong? 我究竟做错了什么?

As others have mentioned, it did parse, you just don't recognise the result. 正如其他人提到的那样,它确实进行了解析,您只是不知道结果。

JSON is a serialisation of an object heirarchy to a string. JSON是将对象层次结构序列化为字符串。

JSON.parse(...) turns a JSON serialisation (string) back into an object heirarchy. JSON.parse(...)将JSON序列化(字符串)变回对象层次结构。

That heirrarchy of objects can't juse be displayed -- it can be traversed! 无法显示杂乱无章的对象-可以遍历它! -- you'll need to encode it into something that can be displayed (for example HTML). -您需要将其编码为可以显示的内容(例如HTML)。

To do that, you traverse the object heirarchy building up an HTML fragment string. 为此,您遍历对象层次结构以构建HTML片段字符串。 Then you can simply add that to the HTML DOM via the innerHTML propery of an existing element (say a container DIV). 然后,您可以简单地通过现有元素(例如容器DIV)的innerHTML属性将其添加到HTML DOM中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM