在回调函数中访问 JSON 数据结构
我有从 Yahoo API 返回的以下数据结构:
cbfunc({
"query": {
"count": 1,
"created": "2011-02-16T00:48:51Z",
"lang": "en-US",
"results": {
"place": {
"woeid": "2487956"
}
}
}
});
在我的代码中,我尝试按如下方式访问它:
$.getJSON(url,function(json)
{
$.each(json.query.results.place, function(i, item)
{
alert(item.woeid);
});
});
但它不起作用。任何帮助将不胜感激。谢谢。
I have the following data structure returning from a Yahoo API:
cbfunc({
"query": {
"count": 1,
"created": "2011-02-16T00:48:51Z",
"lang": "en-US",
"results": {
"place": {
"woeid": "2487956"
}
}
}
});
In my code, I'm trying to access it as follows:
$.getJSON(url,function(json)
{
$.each(json.query.results.place, function(i, item)
{
alert(item.woeid);
});
});
but it is not working. Any help would be much appreciated. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我问这个问题还为时过早。我做了一个像这样的ajax设置:
一切都修复了。好吧,至少我发现了解析错误,然后重新格式化了数据!
抱歉发帖!!!
I was premature in asking this question. I did an ajax setup like so:
and everything was fixed. Well, at least I found out that there was a parse error and then reformatted the data!
Sorry for the post!!!
我认为它是 JSONP 而不是 JSON。您可以通过编写一个名为 cbfunc 的函数来对返回的 json 使用 eval。
I think it is JSONP and not JSON. you could've used an eval on the returned json, by writing a function called cbfunc.