[英]Parse nested JSON
I have the following JSON on a URL: 我在URL上具有以下JSON:
{
"href":"http:\/\/api.rwlabs.org\/v1\/jobs?limit=10",
"time":18,
"links":
{
"self":
{
"href":"http:\/\/api.rwlabs.org\/v1\/jobs?offset=0&limit=10&preset=minimal"
},
"next":
{
"href":"http:\/\/api.rwlabs.org\/v1\/jobs?offset=10&limit=10&preset=minimal"
}
},
"totalCount":2279,
"count":10,
"data":[
{
"id":"1148141",
"score":1,
"href":"http:\/\/api.rwlabs.org\/v1\/jobs\/1148141",
"fields":
{
"title":"Volunteer Renewable Energy Programmes Coordinator"
}
},
{
"id":"1147901",
"score":1,
"href":"http:\/\/api.rwlabs.org\/v1\/jobs\/1147901",
"fields":
{
"title":"Volunteer Project Management Coordinators \/ Intern"
}
}
/* so on*/
And I want get the information inside "data" and inside "fields". 我想在“数据”和“字段”中获取信息。 If I remove the part before data array, I can get some of the values, but fields returns undefined.
如果删除数据数组之前的零件,则可以获得一些值,但字段返回未定义。 Although I also need to have a solution without removing the information before data.
尽管我还需要一个解决方案而不删除数据前的信息。
JS JS
var table = '<table><thead><th>id</th><th>title</th></thead><tbody>';
var obj = $.parseJSON(data);
$.each(obj, function(i, val) {
table += '<tr><td>' + this['id'] + '</td><td>' + this['obj[i].title'] + '</td></tr>';
});
table += '</tbody></table>';
document.getElementById("datalist").innerHTML = table;
(I also do not know how to parse the data from the URL, so for now I am copying the data into the script) (我也不知道如何从URL解析数据,所以现在我将数据复制到脚本中)
[JSFiddle]: http://jsfiddle.net/1v803c3L/1/ Although I have part of the data on the code, even though the entire information is on an URL as seen on the code I posted. [JSFiddle]: http : //jsfiddle.net/1v803c3L/1/尽管我在代码中包含了部分数据,尽管整个信息都在我发布的代码中看到的URL上。
obj.data[i].fields.title
,其中i
是用于索引到数据数组的int
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.