I have a json object as follows:
[{\"Id\":\"1\",\"Item\":\"Apples\",\"PricePerKilo\":\"10.00\"},
{\"Id\":\"3\",\"Item\":\"Oranges\",\"PricePerKilo\":\"12.00\"}]
You must loop! (Also, if fruits
holds the JSON and not the array [it can’t hold both] then you should use jQuery.parseJSON
on it first.)
var i, fruit;
for(i = 0; fruit = fruits[i]; i++) {
if(fruit.Id == 3)
break;
}
fruit
will contain either the fruit with the Id
of 3
or undefined
if it didn’t exist.