当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - retrieve a complex JSON response and display the parts that I want from it

问题描述:

this is the first time I use JSON and underscore.js.

I'm getting a JSON response :

response Object { numFound=12, start=0, docs=[10]}

responseHeader Object { status=0, QTime=1, params={...}}

the docs nested array has another nested array like this

0 { id="23", name="8asjkdnsd",absolute_path="kkskskmasd8234", more... }

.

.

.

9 { id="89234", name="awdcs",absolute_path="qwdacsc", more... }

I want to use underscore.js in my jquery script to convert the response to an array to be able to access any key, value pair when I want to, like if I want to print all the names inside the docs[10]?

I'm trying something like this :

_.each(response.docs.name, function(docs){console.log(response.name);});

but I'm getting undefined and actually I don't know what I'm doing. so any help would be appreciated.

thanks in advance.

网友答案:

About this line of code... you can read the reference of underscore each

_.each(response.docs.name, function(docs){console.log(response.name);});

The first argument of each needs to be an array and I don't think this is the case of response.docs.name, which probably is a String.

分享给朋友:
您可能感兴趣的文章:
随机阅读: