问题描述
我想通过JSONP抓一些数据。用Firebug,我能看到正确返回的数据,但我有一个很难想我怎么也解析它。数据回报确实是一个嵌套数组正确吗? someFunction
的回调函数的名称。这是怎样的数据看起来:
I am trying to grab some data via JSONP. Using Firebug, I am able to see the data properly being returned, but I am having a hard time thinking how I have to parse it. The data return is really a nested array correct? someFunction
is the name of the callback function. This is how the data looks:
someFunction([
{
"title":"Sample Title",
"link":"http://example.com",
"description":"Sample Description",
"publisher":"Sample Publisher",
"creator":"Sample Author",
"date":"Thu, 19 Aug 2010 12:41:29 GMT",
"num_pages":10,
"num_results":"10"
},
]);
只是有点困惑如何正确分析和输出。
Just a little confused about how to properly parse and output.
推荐答案
您不必分析数据。这已经是一个有效的JavaScript对象。例如,要打印的说明属性里面someFunction的第一个对象。
You don't have to parse the data. It is already a valid JavaScript object. For instance, to print the description property for the first object inside someFunction
function someFunction(result) {
alert(result[0].description); // alerts "Sample Description"
}
这篇关于如何解析从远程服务器返回JSONP数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!