Solved

Read JSON with out AJAX (jQuery)

Posted on 2010-11-22
6
648 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

738 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