Solved

Read JSON with out AJAX (jQuery)

Posted on 2010-11-22
6
645 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

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…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to dynamically set the form action using jQuery.

803 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