Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access JSON.parsed object in javascript

I did JSON.parse and getting output in javascript variable "temp" in format like this

{"2222":{"MId":106607,
"Title":"VIDEOCON Semi Automatic Marine 6.8kg",
"Name":"washma01",
}}

I tried like

alert(temp[0][0]);
alert(temp.2222[0].MId);

but not getting output.

How will I access this data in javascript ?

like image 378
mangesh deshpande Avatar asked Oct 15 '09 05:10

mangesh deshpande


1 Answers

alert(temp["2222"].MId);

You can't use numeric indexing, because don't have any actual arrays. You can use dot syntax if the first character of the key is non-numeric. E.g.:

var temp = JSON.parse('{"n2222":{"MId":106607, "Title":"VIDEOCON Semi Automatic Marine 6.8kg", "Name":"washma01", }}');
alert(temp.n2222.MId);
like image 175
Matthew Flaschen Avatar answered Sep 20 '22 02:09

Matthew Flaschen