我正在编写一个应用程序来使用他们的 REST API 和 Square 的 Retrofit 库来控制飞利浦 Hue 智能灯。
问题是,当我调用/lights
响应返回时,使用每个灯光的id
属性作为 json 响应中的键(而不是 jsonapi 响应中典型的灯光对象数组,这似乎是 Retrofit 所期望的) .
这是我正在查看的请求/响应
GET /lights
返回
``` {
"1": {
"state": {
"on": true,
"bri": 144,
"hue": 13088,
"sat": 212,
"xy": [0.5128,0.4147],
"ct": 467,
"alert": "none",
"effect": "none",
"colormode": "xy",
"reachable": true
},
"type": "Extended color light",
"name": "Hue Lamp 1",
"modelid": "LCT001",
"swversion": "66009461",
"pointsymbol": {
"1": "none",
"2": "none",
"3": "none",
"4": "none",
"5": "none",
"6": "none",
"7": "none",
"8": "none"
}
},
"2": {
"state": {
"on": false,
"bri": 0,
"hue": 0,
"sat": 0,
"xy": [0,0],
"ct": 0,
"alert": "none",
"effect": "none",
"colormode": "hs",
"reachable": true
},
"type": "Extended color light",
"name": "Hue Lamp 2",
"modelid": "LCT001",
"swversion": "66009461",
"pointsymbol": {
"1": "none",
"2": "none",
"3": "none",
"4": "none",
"5": "none",
"6": "none",
"7": "none",
"8": "none"
}
}
}```
请注意,它不是返回一个灯光对象数组,而是返回每个与其灯光 ID 相关的灯光对象。
任何人都知道如何用改造来解析这个?