Solved

Read JSON with out AJAX (jQuery)

Posted on 2010-11-22
6
647 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding 1 the value of input "text" every 3 seconds 5 33
Accordion won't close correctly 5 12
Read text on Table 7 25
Prevent certain words from being typed in a form 6 27
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…
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 …
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 learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

740 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