【发布时间】:2017-05-28 23:12:08
【问题描述】:
我的响应 JSON 在理论上遵循 JSON API 规范。我正在尝试使用moshi-jsonapi library 进行解析,但我不知道如何解析some_objects 关系。在SomeType 类中,我有一个成员HasMany<SomeObject> someObjects,并且SomeObject 类以正确的方式注释:
@JsonApi(type = "some_objects")
public class SomeObject extends Resource {
//....
}
但是,在进行解析之后,我将 someObjects 成员设为空。有谁知道为什么?
JSON 就是那个:
"links": {
"self": "someurl/params"
},
"data": [
{
"type": "some_type",
"id": "12345",
"attributes": {
"attr1": 1,
"attr2": 2,
"attr3": 3
},
"relationships": {
"some_objects": {
"data": [
{
"type": "some_objects",
"id": "1"
},
{
"type": "some_objects",
"id": "2"
}
]
}
}
}
],
"included": [
{
"type": "some_objects",
"id": "1",
"attributes": {
"id": "1",
"parentId": "1"
},
"relationships": {
"subobjects": {
"data": [
{
"type": "subobjects",
"id": "2"
}
]
}
}
{
"type": "subobjects",
"id": "2",
"attributes": {
"metadata": {
"code": "AA"
},
"id": "2",
"parentId": "1"
}
}
],
"meta": {
"total": 1,
"totalCount": 1,
"correction": []
}
}
【问题讨论】:
标签: android json json-api moshi