By help my last question got solved but still stuck..
After trying this I got an error on console log..
Error: Syntax error, unrecognized expression: [ { "id": 1, "name": "Bhavik", "phone": 9601109585 }, { "id": 2, "name": "Xyz", "phone": 1234567890 }, { "id": 3, "name": "Abc", "phone": 9876543210 } ]
[Break On This Error]
throw new Error( "Syntax error, unrecognized expression: " + msg );
jQuery code:
var list = { "Persons": data.d };
$(list.Persons).each(function (index)
{
alert( this.id + "\n" + this.name + "\n" + this.phone);
});
JSON array:
[
{
"id": 1,
"name": "Bhavik",
"phone": 9601109585
},
{
"id": 2,
"name": "Xyz",
"phone": 1234567890
},
{
"id": 3,
"name": "Abc",
"phone": 9876543210
}
]
I want to loop through the list.. Any ideas..
EDIT After @Vucko's suggestion I tried replacing data.d
by the the JSON array itself and to my surprise it worked JSFiddle.. Any reason and solution for it..
Solved changed var list = { "Persons": $.parseJSON(data.d)};
.. JSON response is not enough I guess.. We need to parse it also..