0

I managed to get the JSON array into (look http://yrs2013.bugs3.com/mpapp/getSTORY.php?url=http%3A%2F%2Fcontent.guardianapis.com%2Fsearch%3Fq%3DJohn%20Stevenson%20mp%26page-size%3D3%26format%3Djson there for the array details), Javascript as a JS object - however now when i try and call a piece of data from the array it comes back as 'undefined'.. Any tips? :)

JS Code:

$.getJSON('getSTORY.php?url='+ url2, function(response) 
console.log(response);
//logs the response, comes up as object in the log;
var e = response.status;
//when e is logged it just says 'undefined' 
console.log(e);

In the log the object looks like drop down menus, which is different to my previous attempts of similar things as they came back from the PHP as text. I have tried JSON.parse but however that came back with the undefined o error! :l any help gratefully accepted! Thanks!

Reality
  • 3
  • 1

1 Answers1

1

By looking at your JSON structure, I believe you need response.response.status. The first response is a variable holding your whole object, which contains a single response property with status inside (as well as results, etc).

bfavaretto
  • 71,580
  • 16
  • 111
  • 150
  • thank you this works perfectly for status! However whenever I select to try to get the data in results section, for example "webTitle", the error comes as "cannot read property'0' of undefined... the code i use is " var e = response.response.results.id[0].webTitle" Any ideas? thanks! – Reality Aug 08 '13 at 22:24
  • EDIT: think ive got it aha! :) – Reality Aug 08 '13 at 22:26
  • See http://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json, it's all there @Reality – bfavaretto Aug 08 '13 at 22:26