Reputation: 37909
I am getting this back from the server:
{"Message":"The request is invalid.","ModelState":{"":["Name [email protected] is already taken.","Email '[email protected]' 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.
Upvotes: 1
Views: 342
Reputation: 1255
You can reference the first item of your unnamed array like this:
var jsonString = {"Message":"The request is invalid.","ModelState":{"":["Name [email protected] is already taken.","Email '[email protected]' is already taken."]}};
console.log('first item: ', jsonString.ModelState[''][0]);
Upvotes: 2
Reputation: 143
if test = {"Message":"The request is invalid.","ModelState":{"":["Name [email protected] is already taken.","Email '[email protected]' is already taken."]}}
then your array is at test['ModelState'][""]
Upvotes: 1