admin管理员组

文章数量:1287555

I have a small question :

If I have a JSON array:

{
"cate_user_res_id": "4",
"from": "url",
"mimetype": "image/jpeg",
"ext": "jpg",
"res_name": ".jpg",
"user_id": "1",
"file_size": 55966,
"created": "2011-12-19 03:29:45",
"type": "i"
}

How can i get data of ["res_name"] index?

I alert data['res_name'] it result undefined.

Thanks for any suggestion!

I have a small question :

If I have a JSON array:

{
"cate_user_res_id": "4",
"from": "url",
"mimetype": "image/jpeg",
"ext": "jpg",
"res_name": "http://watermarked.cutcaster./cutcasterglobe.jpg",
"user_id": "1",
"file_size": 55966,
"created": "2011-12-19 03:29:45",
"type": "i"
}

How can i get data of ["res_name"] index?

I alert data['res_name'] it result undefined.

Thanks for any suggestion!

Share Improve this question edited Dec 19, 2011 at 9:37 David Z 132k29 gold badges263 silver badges284 bronze badges asked Dec 19, 2011 at 8:35 johnITBonucjohnITBonuc 1611 gold badge2 silver badges10 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

You need to parse to Javascript object first from the JSON array.

//var data = JSON.parse("<JSON string>");
var data = JSON.parse('{ "res_name" : " stackoverflow" }');

//Then you can get your value easily.
console.log(data.res_name);
console.log(data['res_name']);

Check this tutorial, would be helpful: http://geochalkboard.wordpress./2009/08/03/reading-json-data-with-dojo/

var obj = dojo.fromJson(json);
console.log(obj.res_name);

本文标签: javascriptHow can I get data from an Json array in DOJOStack Overflow