How to get reference to unnamed array from json

时间:2015-09-30 23:11:29

标签: javascript json

I am getting this back from the server:

{"Message":"The request is invalid.","ModelState":{"":["Name greg@gmail.com is already taken.","Email 'greg@gmail.com' is already taken."]}}

How do I reference the first item of the array in JS? The debugger tells me that ModelState is an object, but there seems to be no name for the array.

2 个答案:

答案 0 :(得分:2)

var jsonString = {"Message":"The request is invalid.","ModelState":{"":["Name greg@gmail.com is already taken.","Email 'greg@gmail.com' is already taken."]}};

console.log(jsonString.ModelState[''][0]);

http://jsfiddle.net/turbopipp/rnp9rabc/

答案 1 :(得分:1)

if test = {"Message":"The request is invalid.","ModelState":{"":["Name greg@gmail.com is already taken.","Email 'greg@gmail.com' is already taken."]}}

then your array is at test['ModelState'][""]

相关问题