Solved

Read JSON with out AJAX (jQuery)

Posted on 2010-11-22
6
643 Views
Last Modified: 2012-08-13
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.
0
Comment
  • 3
  • 2
6 Comments
 
LVL 15

Expert Comment

by:crisco96
ID: 34191242
Use the eval function

http://www.json.org/js.html
0
 
LVL 1

Author Comment

by:catonthecouchproductions
ID: 34191287
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.

0
 
LVL 1

Author Comment

by:catonthecouchproductions
ID: 34191305
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
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 82

Expert Comment

by:hielo
ID: 34191347
>>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/
0
 
LVL 15

Accepted Solution

by:
crisco96 earned 500 total points
ID: 34191357
So going from the example from the link above you have:

var myObject = eval('(' + myJSONtext + ')');

where myObject will be a javascript object containing the result of myJSONtext

So you would use it with:

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

Basically after calling eval myObject will be what you would have expected if you would have called getJSON.

0
 
LVL 1

Author Comment

by:catonthecouchproductions
ID: 34191664
appreciate it, I am going to go test this out. Thank you for explaining this
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now