Andrew
Andrew

Reputation: 252

Unable to parse Json data with jquery

Very simple question that's been dogging me. I have a handler that returns the following formatted JSON (and it has tested as valid):

[
{
"Field1": 1234,
"Field2": "My Name",
"Field3": 321,
"Field4": 456,
"Field5": 789,
"Field6": "Home",
"Field7": "123 Main St",
"Field8": "Updated 10/15/14",
"Field9": null,
"Field10": null
}
]

When I try to grab a value from this via:

var json = $.parseJSON(data);
var test = data.Field1;

I get 'undefined' for every value I test. The datatype on the ajax call is 'text' and 'data' in the above context represents the JSON object shown above.

Upvotes: 0

Views: 698

Answers (1)

Omidam81
Omidam81

Reputation: 1917

your JSON string is array not object, so after parsing it, you need to access items like array.

data[0].Field1

Upvotes: 4

Related Questions