Created
February 4, 2011 02:25
-
-
Save thurloat/810642 to your computer and use it in GitHub Desktop.
2 Options for parsing some JSON data.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Long and Dreary. | |
*/ | |
var json = xml2json.parser(response_text), | |
query_result = json.envelope.body.queryresponse.result, | |
users = []; | |
// Build up a list of {{sd.User}}s to return to the view. | |
if(query_result.size == 1){ | |
// Only a single user returned from the search | |
users.push(new sd.User(query_result.records)); | |
} else if(query_result.size > 0){ | |
for (var query_i=0; query_i < query_result.records.length; query_i++) { | |
users.push(new sd.User(query_result.records[query_i])); | |
}; | |
} | |
return users |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Short and Sweet. | |
*/ | |
var json = xml2json.parser(response_text), | |
query_result = json.envelope.body.queryresponse.result, | |
records = [].concat(query_result.records), | |
users = []; | |
// Build up a list of {{sd.User}}s to return to the view. | |
for (var query_i=0; query_i < records.length; query_i++) { | |
users.push(new sd.User(records[query_i])); | |
}; | |
return users; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment