0

for example json response is like this:

{testing:[
    {"title":"Hello","text":"Hello Test!"},
    {"title":"World","text":"World Test!"}
]}

how can I parse this json data using jQuery getJSON and jQuery.each function to print this data in separate div tags?

3
  • Euh what date? And please take a look at the related question because this seems like an already asked question. Commented Apr 14, 2011 at 14:30
  • sorry not date. DATA. JSON RESPONSE Commented Apr 14, 2011 at 14:32
  • 1
    That is not valid JSON. The word testing should be in double quotes. Commented Apr 14, 2011 at 14:35

2 Answers 2

0

$.getJson(); expects data to be properly formatted, so if u are using php u need to use json_encode($array)

and you should be fine, you don't need to parse anything.

Sign up to request clarification or add additional context in comments.

Comments

0

I think this might work. It makes a call to the server for your json then loops through the testing array and displays the contents.

var data = {id: userId}; //Use null if your server needs no info
jQuery.getJSON( "/mylink/getjson", data, function(json){
    if(typeof(json.testing) != "undefined"){
        $(json.testing).each(function(){
            document.write(this.title);
            document.write(this.text);
        });
    }
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.