Link to home
Start Free TrialLog in
Avatar of catonthecouchproductions
catonthecouchproductionsFlag for United States of America

asked on

Read JSON with out AJAX (jQuery)

I have a JSON object with data and i am trying to take that object and read it without using getJSON. The JSON is already loaded on the page. It is not on the callback of an AJAX call using jQuery.

I have worked with AJAX and jQuery to display JSON after making a call, but not sure how to read it if it is already on the page.

Any ideas? Thanks.
Avatar of crisco96
crisco96
Flag of United States of America image

Use the eval function

http://www.json.org/js.html
Avatar of catonthecouchproductions

ASKER

Could you elaborate a little bit?

My goal is to read the JSON and update the input with the value of the json

$(#input).val(object.DataName);

Something along those lines for each of my inputs.

Starting to make a bit more sense, never used that function before, I checked out the simple example here: http://www.w3schools.com/jsref/jsref_eval.asp
Avatar of hielo
>>I have a JSON object with data and i am trying to take that object and read it
Do you have:
a. an ACTUAL object or
b.a json string that you need to convert to json?

If a, then you can use a for-in construct to iterate over the object properties.
If b, then you can use $.parseJSON to convert the json string to an object.
http://api.jquery.com/jQuery.parseJSON/
ASKER CERTIFIED SOLUTION
Avatar of crisco96
crisco96
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
appreciate it, I am going to go test this out. Thank you for explaining this