Solved

Read JSON with out AJAX (jQuery)

Posted on 2010-11-22
6
644 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
This article discusses how to create an extensible mechanism for linked drop downs.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

911 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

24 Experts available now in Live!

Get 1:1 Help Now