I am developing JMAKI widgets,my task is to display the json data in a html page through javascript.
What's the best way to access the json data through javascript?
Oded
501k102 gold badges901 silver badges1k bronze badges
3 Answers 3
if you have the json object already just access as you would with a normal object:
// Creating the JSON object from string
var obj = JSON.parse('{"attr1": 10, "attr2": "Some value"}');
// You can access it like this
var a = obj.attr1;
var b = obj.attr2;
console.log(a, b); // Will print 10, "Some value"
For me that is the best way to access a JSON object (not the only one) it feels more natural for me.
answered Aug 20, 2012 at 21:00
Ricardo Murillo
2,9151 gold badge20 silver badges12 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You can use
object = eval("(" + json_string + ")")
or
object = JSON.parse(json_string)`
answered Sep 15, 2010 at 9:18
jcubic
67.1k58 gold badges252 silver badges466 bronze badges
Comments
default