Bing 映射 JSON 不使用 JSON.parse 进行解析
Bing Maps JSON not parsing with JSON.parse
我正在尝试在Windows应用商店应用程序中使用Bing Maps进行反向地理编码。我的请求(使用 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"
}
但是,当我对数据调用 JSON.parse 并尝试显示它时,它返回的只是
[object Object]
我做错了什么?
正如其他人所提到的,它确实解析了,你只是不认识结果。
JSON
是对象层次结构对字符串的序列化。
JSON.parse(...)
将 JSON 序列化(字符串)转换回对象层次结构。
对象的层次结构不能显示 - 它可以被遍历!- 你需要将其编码为可以显示的东西(例如HTML)。
为此,您需要遍历对象层次结构,构建一个 HTML 片段字符串。然后,您可以通过现有元素(例如容器 DIV)的innerHTML
属性将其简单地添加到 HTML DOM 中。
相关文章:
- JSON.parse没有'不能使用Javascript
- Javascript JSON.parse not working
- 当其他解析器认为意外的令牌有效时,json.parse会失败
- 无法将JSON.parse与JSON_encode中的结果一起使用
- 在JSON.parse Javascript中字符串化Java对象抛出错误
- JSON.parse,已经在try/catch块中,仍然抛出语法错误
- 停止JSON.parse()从JSON字符串数据中删除尾随零
- JSON.parse给了我一个错误,但JSONLint说它'是一个有效的json
- 从JSON.parse获取元素
- JSON.parse:应为''或'}'在对象的属性值之后
- AJAX语法错误:JSON.parse:意外字符
- 如何避免JSON.stringify在特殊情况下返回undefined,从而为JSON.parse创建字符串失败
- 使用JSON.parse时出现无效字符javascript错误
- 动态地将过滤器应用于 JSON.parse()
- 为什么 JSON.parse 给出无效的字符
- 想要将 JSON 字符串传递给 javascript 变量 [ JSON.parse(),eval()] 对我不起作用,
- 使用 JSON.parse 将字符串(变量)转换为对象,错误意外标记
- “JSON.parse(str)”返回“意外令牌c”,但str是一个字符串
- AngularJS json.parse 在 json 数据的第 1 行第 1 列处意外的数据结尾
- 带有Ajax请求的Javascript JSON.parse函数n〃;新行转义字符