1

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
asked Sep 15, 2010 at 6:18

3 Answers 3

2

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
Sign up to request clarification or add additional context in comments.

Comments

0

use eval(json-object), if you trust the source, or you can use the json parser here

answered Sep 15, 2010 at 6:29

Comments

0

You can use

object = eval("(" + json_string + ")")

or

object = JSON.parse(json_string)`
answered Sep 15, 2010 at 9:18

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.