titanium - parsing JSON on appcelerator -


i have webservice this:

{"person":{"name account":"jhon doe","image":"image/test","adress":"new york 43","recomendations":"40"}} 

this i'm trying do, when print datos whole json when try print name or image don't anything

var urll = "example.com/example"; var json; var xhrr = ti.network.createhttpclient({     onload: function() {         json = json.parse(this.responsetext);         var datos = json.stringify(json);         var medicos = datos;         ti.api.info("json! "+datos); } }); xhrr.open('get', urll); xhrr.send(); 

i tried datos[0].person, datos.person nothing

you have understand difference between string contains json representation of object - , object itself.

your json variable contains object (which json.parse(...) - convert text string object). on object can refer attributes discovered. can in 2 ways:

json.person.address json.person['name account'] 

i suggest try avoid attributes names not valid identifiers (as latter of two) makes little more difficult use them - e.g. not allowing dot notation.

your datos variable on other hand contains string representation of json object (as json.stringify(...) - convert object string representation). means datos same this.responsetext (since first parse , stringify back).

so json.stringify(...) brilliant way make object "human readable" need object work data.

hope clarifies terms little ;-)

/john


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -