我试图访问OpenWeatherMap请求返回的JSON数组 JSON数据是:
{ "city":
{ "id": 3171457, "name": "New York", "coord": { "lon": 0.32898, "lat": 4.802662 }, "country": "US", "population": 0, "sys": { "population": 0 } },
"cod": "200", "message": 0.0317, "cnt": 40,
"list": [ { "dt": 1483552800, "main": { "temp": 277.28, "temp_min": 275.705, "temp_max": 277.28, "pressure": 1013.85, "sea_level": 1021.42, "grnd_level": 1013.85, "humidity": 93, "temp_kf": 1.57 }, "weather": [ { "id": 800, "main": "Clear", "description": "clear sky", "icon": "01n" } ], "clouds": { "all": 0 }, "wind": { "speed": 4.74, "deg": 269.002 }, "sys": { "pod": "n" }, "dt_txt": "2017-01-04 18:00:00" },
...
如果我在模板{{payload.list}}中使用,我会看到[object Object]的列表 但是,如果我使用{{payload.list [0]}}或{{payload.list [0] .main}},我什么也看不见 - 我的猜测是单个[对象]。 我如何访问第一个成员和内部成员?
答案 0 :(得分:2)
模板节点使用mustache
格式,在此处记录:https://mustache.github.io/mustache.5.html
要访问数组值,您应该使用以下语法:
{{ payload.list.0 }}
和
{{ payload.list.0.main }}