getjson - jQuery JSON parse: undefined object -
i have used jquery's getjson()
data server. response looks me. how looks
{"user" :[{"username":"nupac"},{"username":"nupac2"}]}
when alert(objects.keys(jsonresponse));
user
in alert box fine when try access data jsonresponse['user']
undefined
.
why getting undefined? think should array of objects.
edit:
here code real url,
function getlmslinks(email){ $.getjson("url?student=" + email, function(d) { alert(object.keys(d)); alert(d['user']); }).fail( function(d, textstatus, error) { //alert("fail " + textstatus + " error " + error); console.error("getjson failed, status: " + textstatus + ", error: "+error) }); }
are looking this
var jsonresponse = { "user": [{ "username": "nupac" }, { "username": "nupac2"}] } alert(jsonresponse.user[0].username);
if string, first need make object using
jsonresponse =jquery.parsejson(jsonresponse);
then can use like
alert(jsonresponse.user[0].username);
edit
$.getjson("http://prinyautils.appspot.com/getlmsurl?student=" + email, function(d) { alert(object.keys(d)); alert(d.user[0].username); }).fail( function(d, textstatus, error) { //alert("fail " + textstatus + " error " + error); console.error("getjson failed, status: " + textstatus + ", error: "+error) });
Comments
Post a Comment