在没有参考的情况下改造对列表的访问
Retrofit access to list withouth reference
我有这个 JSON,但在尝试访问列表时我不知道如何传递值 "Serialized",我没有任何值。
我在 android 上工作。
有谁知道怎么访问?
谢谢。
[
{
"id": “111”,
"dateStart": "2020-02-26T00:00:00+01:00",
"dateEnd": "2020-02-26T01:30:00+01:00",
"sectionId": 0,
"description": “Test”,
"comment": “Test comment”,
"emissionType": “A”,
"priority": 5,
"audios": [],
"idCollection": “1”
},
{
"id": “222”,
"dateStart": "2020-02-26T00:00:00+01:00",
"dateEnd": "2020-02-26T01:30:00+01:00",
"sectionId": 0,
"description": “Test”,
"comment": “Test comment”,
"emissionType": “B”,
"priority": 5,
"audios": [],
"idCollection": “12”
}
]
public static Gson getGSONBuilder()
{
Gson gson = new GsonBuilder().
registerTypeAdapter(Double.class, new JsonSerializer<Double>()
{
@Override
public JsonElement serialize(Double src, Type typeOfSrc,
JsonSerializationContext context) {
if (src == src.longValue())
return new JsonPrimitive("" + src.longValue());
return new JsonPrimitive("" + src);
}
}).create();
return gson;
}
String responseString=getGSONBuilder().toJson(response.body());//response is Retrofit
response
在改造中只需调用 ArrayList> 作为响应,您将所有 arraylist 数据及其键和值放入 hashmap 中。
for(int i=0;i<responce.body().size;i++){
arrlist.add(responce.body().get(i))
}
我有这个 JSON,但在尝试访问列表时我不知道如何传递值 "Serialized",我没有任何值。 我在 android 上工作。 有谁知道怎么访问? 谢谢。
[
{
"id": “111”,
"dateStart": "2020-02-26T00:00:00+01:00",
"dateEnd": "2020-02-26T01:30:00+01:00",
"sectionId": 0,
"description": “Test”,
"comment": “Test comment”,
"emissionType": “A”,
"priority": 5,
"audios": [],
"idCollection": “1”
},
{
"id": “222”,
"dateStart": "2020-02-26T00:00:00+01:00",
"dateEnd": "2020-02-26T01:30:00+01:00",
"sectionId": 0,
"description": “Test”,
"comment": “Test comment”,
"emissionType": “B”,
"priority": 5,
"audios": [],
"idCollection": “12”
}
]
public static Gson getGSONBuilder()
{
Gson gson = new GsonBuilder().
registerTypeAdapter(Double.class, new JsonSerializer<Double>()
{
@Override
public JsonElement serialize(Double src, Type typeOfSrc,
JsonSerializationContext context) {
if (src == src.longValue())
return new JsonPrimitive("" + src.longValue());
return new JsonPrimitive("" + src);
}
}).create();
return gson;
}
String responseString=getGSONBuilder().toJson(response.body());//response is Retrofit
response
在改造中只需调用 ArrayList> 作为响应,您将所有 arraylist 数据及其键和值放入 hashmap 中。
for(int i=0;i<responce.body().size;i++){
arrlist.add(responce.body().get(i))
}