0

I'm using an AJAX request to return the following string:

{"city":"Seattle","country":"US","weather":[{"icon":"10d","temperature":46.6},{"icon":"13d","temperature":43.16},{"icon":"13d","temperature":43.43},{"icon":"13d","temperature":40.55},{"icon":"01d","temperature":37.33},{"icon":"10d","temperature":41.86},{"icon":"10d","temperature":43.32}]}

I want to split that string so I can get each of the icon string values ("10d", "13d" etc) as well as each of the temperatures ("46.6", "43.16" etc) but I'm not entirely sure how to go about doing that. It seems like I would need to split the string but I'm not sure if that's the best way to go about it

omarjmh
  • 13,632
  • 6
  • 34
  • 42
  • Might be sent as JSON string but when parsed to javascript object you use object and array methods on it – charlietfl May 15 '16 at 03:05
  • So if I had a var containing the String from the JSON like var weather = {"city":"Seattle","country":"US","weather":[{"icon":"10d","temperature":46.6},{"icon":"13d","temperature":43.16},{"icon":"13d","temperature":43.43},{"icon":"13d","temperature":40.55},{"icon":"01d","temperature":37.33},{"icon":"10d","temperature":41.86},{"icon":"10d","temperature":43.32}]}; I could do like var json = JSON.parse(weather); and then alert(json.icon) would return the icon value? – john herman May 15 '16 at 03:13

0 Answers0