Iterate Through Array in JSON Object
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2018 09:31 AM
I am having problems with pulling out the data in the "addresses" array. Below is what my json looks like:
"{\"processing_time_milliseconds\": 714, \"addresses\": [{\"address1\": \"7899 hello road\", \"address2\": \"\", \"city\": \"Neverland\", \"state_or_province\": \"CA\", \"postal_code\": \"23487\", \"postal_code_extension\": \"3352\", \"county\": \"Land\", \"country_code\": \"US\", \"latitude\": \"22.43456\", \"longitude\": \"-45.67977\"}]}"
And here is the snipped of my code:
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var parser = new JSONParser();
var parsed = parser.parse(responseBody);
for (i = 0; i < parsed.addresses.length; i++) {
gs.print(parsed.addresses[i].address1);
}
It is never making into my for loop because the length is returning undefined. I am wanting to be able to parse out each individual piece of data to store other places (address, state, city, zip, etc.). Am I missing something here as to why this is not working?
Thanks!
Labels:
- Labels:
-
Scripting and Coding
10 REPLIES 10

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2018 11:33 AM
So looks like your REST API has a problem. You are not receiving any response
Please mark this response as correct or helpful if it assisted you with your question.