【发布时间】:2015-04-26 01:59:09
【问题描述】:
我收到这个 JSON 字符串:
{
"response": [
346,
{
"id": 564,
"from_id": -34454802,
"to_id": -34454802,
"date": 1337658196,
"post_type": "post"
},
{
"id": 2183,
"from_id": -34454802,
"to_id": -34454802,
"date": 1423916628,
"post_type": "post"
},
{
"id": 2181,
"from_id": -34454802,
"to_id": -34454802,
"date": 1423724270,
"post_type": "post"
}]
}
我创建了以下类:
public class Response {
@SerializedName("response")
ArrayList<Post> posts;
}
public class Post {
int id;
int from_id;
int to_id;
long date;
String post_type;
}
当我尝试解析响应时,出现错误:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was NUMBER at line 1 column 19 path $.response[0]
这是因为数组的第一个元素是数字。需要哪种型号才能正常运行?
【问题讨论】:
-
您的
JSON响应字符串无效。你可以在这里查看json.parser.online.fr -
您希望如何将数字 346 转换为
Post类型的对象?
标签: android json parsing gson retrofit