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?

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.

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

Comments

0

You can use

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

or

object = JSON.parse(json_string)`

Comments

Your Answer

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.