私はいくつかの同様の質問があることを知っていますが、それらのどれも私の問題に一致しません。私はこのようになり、サーバからのJSONレスポンスを持っている:Retrofit予想通りBEGIN_ARRAYでしたが、BEGIN_OBJECT例外でした
{
"data": {
"list": {
"beacons": [
{
"id": 56,
"beacon_id": "56",
"bridge_id": null,
"mesh_id": null,
"name": "Test beacon wcx",
"location": "test",
"mac_address": "e6:f5:8a:94:b8:c7",
"firmware": "1.1",
"pcb_revision": "2.0",
"battery_level": null,
"password": "0000",
"ib": {
"turn_on": "1",
"major": "300",
"minor": "10",
"tx_power": "4",
"interval": "400",
"uuid": "dae19960-18ea-11e5-8ff0-0002a5d5c521",
"secure_uuid": "0"
},
"euid": {
"turn_on": "0",
"namespace": null,
"instance": null,
"tx_power": null,
"interval": null
},
"eeid": {
"turn_on": "0",
"tx_power": null,
"interval": null
},
"eurl": {
"turn_on": "0",
"tx_power": null,
"interval": null,
"url": null
},
"etlm": {
"turn_on": "0",
"tx_power": null,
"interval": null
}
},
{
"id": 57,
"beacon_id": "57",
"bridge_id": "13",
"mesh_id": "278",
"name": "Marta B",
"location": "lk",
"mac_address": "e1:4b:64:c3:80:e2",
"firmware": "2.1",
"pcb_revision": "2.0",
"battery_level": "97",
"password": "0000",
"ib": {
"turn_on": "1",
"major": "300",
"minor": "6",
"tx_power": "0",
"interval": "0",
"uuid": "dae19960-18ea-11e5-8ff0-0002a5d5c521",
"secure_uuid": "0"
},
"euid": {
"turn_on": "0",
"namespace": null,
"instance": null,
"tx_power": null,
"interval": null
},
"eeid": {
"turn_on": "0",
"tx_power": null,
"interval": null
},
"eurl": {
"turn_on": "0",
"tx_power": null,
"interval": null,
"url": null
},
"etlm": {
"turn_on": "0",
"tx_power": null,
"interval": null
}
},
{
"id": 58,
"beacon_id": "58",
"bridge_id": null,
"mesh_id": null,
"name": "Marta C",
"location": "abcdlk",
"mac_address": "3c:cf:82:8a:e7:fe",
"firmware": "2.1",
"pcb_revision": "2.0",
"battery_level": "99",
"password": "0000",
"ib": {
"turn_on": "1",
"major": "300",
"minor": "39",
"tx_power": "7",
"interval": "400",
"uuid": "dae19960-18ea-11e5-8ff0-0002a5d5c521",
"secure_uuid": "0"
},
"euid": {
"turn_on": "0",
"namespace": null,
"instance": null,
"tx_power": null,
"interval": null
},
"eeid": {
"turn_on": "0",
"tx_power": null,
"interval": null
},
"eurl": {
"turn_on": "0",
"tx_power": null,
"interval": null,
"url": null
},
"etlm": {
"turn_on": "0",
"tx_power": null,
"interval": null
}
}
],
"bridges": [
{
"id": 13,
"name": "Test bridge wcx",
"location": "netizens",
"mac_address": "c9:1d:76:cc:a7:ca",
"ib": {
"turn_on": 1,
"major": "100",
"minor": "102",
"tx_power": "6",
"interval": "400",
"uuid": "dae19960-18ea-11e5-8ff0-0002a5d5c521",
"secure_uuid": 0
},
"euid": {
"turn_on": "0",
"namespace": null,
"instance": null,
"tx_power": null,
"interval": null
},
"eeid": {
"turn_on": "0",
"tx_power": null,
"interval": null
},
"eurl": {
"turn_on": "0",
"tx_power": null,
"interval": null,
"url": null
},
"etlm": {
"turn_on": "0",
"tx_power": null,
"interval": null
}
}
]
}
},
"ver": 1,
"time": 1475576646,
"status": 1,
"status_msg": ""
}
私のモデルクラスは次のようになります。
はpublic class BeaconResponse {
@Expose
public DataBeacon dataBeacon;
@Expose
public int ver;
@Expose
public long time;
@Expose
public int status;
@Expose
public String status_msg;
DataBeaconは、ビーコンや橋のリストはオブジェクトいます
@Table(name = "dataBeacon", id = "_id")
public class DataBeacon extends Model {
@Column(name = "beacon",onUpdate = Column.ForeignKeyAction.CASCADE, onDelete = Column.ForeignKeyAction.CASCADE)
public List<BeaconsModel> beacons;
@Column(name = "bridge",onUpdate = Column.ForeignKeyAction.CASCADE, onDelete = Column.ForeignKeyAction.CASCADE)
public List<BridgeModel> bridges;
}
jsonを入手するための私のインターフェイスは次のとおりです。
@GET("/api/mobile/{language}/{apiVersion}/beacons/list")
void beaconsList(Callback<BasicResponse<BeaconsListResponse>> callback);
public class BeaconsListResponse {
@Expose
public List<BeaconResponse> list;
}
私の意見では、すべて正しく動作するはずですが、まだ例外が発生しています:Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 18 path $.data.list
。私はなぜ、モデルの構造が正しいべきかを知らない。