0

I have a json data which looks something like this

[{"id":"1","name":"Muslin","image1":"muslin.jpg"},{"id":"72","name":"Gagra choli","image1":"gagra choli.jpg"},{"id":"73","name":"Lahenga saree","image1":"lahenga saree.jpg"},{"id":"74","name":"Ao dai","image1":"Ao dai.jpg"},{"id":"75","name":"Brocade","image1":"brocade.jpg"},{"id":"77","name":"Button","image1":"button.jpg"},{"id":"78","name":"Bathrobe","image1":"Bathrobe.jpg"},{"id":"79","name":"Bathtowel","image1":"Bathtowel.jpg"},{"id":"80","name":"Cassock","image1":"cassock.jpg"},{"id":"81","name":"Shirt","image1":"shirt.jpg"},{"id":"82","name":"Dolce and Gabanna","image1":"dolce_and_gabanna.jpg"},{"id":"83","name":"asasa","image1":"1009578_1392050054339713_1292927121_o.jpg"},{"id":"84","name":"knbdfjhbjhbvjh","image1":"images_(1)10.jpg"}]

now i used some code like this

var obj=$.parseJSON(JSON.stringify(res));
                $('#response').html(obj.id);

But the console says that the obj.id is undefined

4

2 回答 2

1

var obj是一个对象数组。所以你需要使用 index 。

$('#response').html(obj[0].id);
于 2013-10-29T06:12:03.003 回答
0
var obj=$.parseJSON(JSON.stringify(res));

您将对象字符串化为字符串,然后将其解析回对象。为什么不直接使用res呢?

res是一个数组,如果要获取id,则必须使用索引。

例如:

$('#response').html(res[0].id);
于 2013-10-29T06:11:56.733 回答