mercredi 25 mars 2015

Printing JSON properties


I am currently trying to send a user information about a JSON object that I've recieved from an API. An example of the format is



[
{
"lang_code": "eng",
"site_language": "1",
"name": "English"
},
{
"lang_code": "afr",
"site_language": "1",
"name": "Afrikaans"
},
{
"lang_code": "ale",
"site_language": "0",
"name": "Aleut"
},
]


I want to be able to access the lang_code property of every single language and send it. I've tried to use



var languageCodes;
var languageResult = body.lang_code; //body is the result from a request.get({ ... })
for(var codes in languageResult) {
languageCodes = languageResult[codes];
}


Object.keys does nothing, as it just sends 72 numbers to me. Any thoughts?


On a side note, I also want people to be able to type "!langages [my command] eng" for example, and it sends "English". Any way to do that?





Aucun commentaire:

Enregistrer un commentaire