ajax - Can't read values from JSON Array in Javascript -


i'm coding script latest posts webpage display them on webpage. created php script create json array script read from. script reads json fine (this json we're talking about:

[ {     "id":18,     "title":"linktest",     "content":"<a href=\"http:\/\/www.youtube.com\/\">dies ist ein link<\/a>",     "datetime":"2014-04-12t17:20:30.000z"     }, {     "id":4,     "title":"noch ein test",     "content":"dies ist noch ein test!",     "datetime":"2014-04-11t14:11:35.000z"     }, {     "id":1,     "title":"test",     "content":"aloha leute,\r\n<p>das ist ein testpost!<\/p>",     "datetime":"2014-04-11t11:09:43.000z"     }  ] 

now, odd reason cannot read values json array doing example: response[1] ("response" being variable i've assigned array to) because that's giving me white space when i'm trying output it. know solution problem?

edit: here's javascript code:

//the replace display data without html tags, testing purposes var response = json.parse(xhr.responsetext).replace(/[\u00a0-\u9999<>\&]/gim, function(i) {     return '&#'+i.charcodeat(0)+';';     });     var lol = document.getelementbyid("lol");     lol.innerhtml = response; 

you need convert received string actual json object before trying access it:

var jsonobject = json.parse(jsonstring);  //now can access this: jsonobject[0].title 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -