A webservice returns this JSON below
[
{
"companyuserId": "2",
"name": "mike jones",
"superiorname": null,
"departmentId": "26",
"departmentname": "Design",
"companyId": "06",
"UDID": "8df912053a16ab2b4c66a",
"isActive": "1",
"devicetoken": "e8a4c1fad76b45d918f6745bfe60d32a81504",
"email": "mike@yahoo.co.uk",
"phone": "5456465465654"
}
]
Thought it would be straight forward
name = data.name;
phone = data.phone;
email = data.email;
departmentname = data.departmentname;
companyId = data.companyId;
But I’m getting undefined, How else can I do this? I think maybe the data maybe in string format because when I alert data I get the result as pasted above rather than object: Object
That is an
array of Objects.. And the Object is theFirst iteminside an array.. So you need to use the index to access the object inside it..So instead of
name = data.name;try thisname = data[0].name;