Java Gson:应为begin_数组,但为字符串
我在解析JSON数据时遇到以下错误: 应为begin_数组,但在第1行第34列为字符串 我找不到解决办法。我的JSON如下所示:Java Gson:应为begin_数组,但为字符串,java,android,json,gson,Java,Android,Json,Gson,我在解析JSON数据时遇到以下错误: 应为begin_数组,但在第1行第34列为字符串 我找不到解决办法。我的JSON如下所示: {"result":0,"count":2,"records":"[{\"name\":\"name1\", \"id\":\"28\", \"photo\":\"\\\/gallery\\\/c9\\\/f0f8\\\/95fb\\\/c9f0f895fb98ab9159f51fd0297e236d\\\/28\\\/tb_uykzubjqmxbv6
{"result":0,"count":2,"records":"[{\"name\":\"name1\",
\"id\":\"28\",
\"photo\":\"\\\/gallery\\\/c9\\\/f0f8\\\/95fb\\\/c9f0f895fb98ab9159f51fd0297e236d\\\/28\\\/tb_uykzubjqmxbv6zkogdsd_c64962310e572f5e8a4c73a44a4fa3dd.jpg\"},{\"name\":\"name2\",
\"id\":\"134\",
\"photo\":\"\\\/gallery\\\/c9\\\/f0f8\\\/95fb\\\/c9f0f895fb98ab9159f51fd0297e236d\\\/134\\\/tb_23ffxuw9-5ys4iqtwztz_610982fa52cca03412dbc84ab0ea5e18.jpg\"}]"}
这是我的PersonContent课程:
public class PersonContent {
@SerializedName("result")
public int result;
@SerializedName("count")
public int count;
@SerializedName("records")
List<Person> records;
public List<Person> getRecords() {
return records;
}
public void setRecords(List<Person> records) {
this.records = records;
}
public void setResults(int result) {
this.result = result;
}
public int getResults(){
return result;
}
public void setCount(int count) {
this.count = count;
}
public int getCount(){
return count;
}
下面是我反序列化前面提到的JSON数据的代码
private void Parse(){
InputStream source = retrieveStream(url);
Gson gson = new Gson();
Reader reader = new InputStreamReader(source);
personlist = gson.fromJson(reader, PersonContent.class);
}
我已经尝试了在这里找到的所有解决方案,但找不到完全相同的JSON。
还有以下内容:错误出现在您收到的json中:
{"result":0,"count":2,"records":"[{\"name\":\"name1\",
\"id\":\"28\",
\"photo\":\"\\\/gallery\\\/c9\\\/f0f8\\\/95fb\\\/c9f0f895fb98ab9159f51fd0297e236d\\\/28\\\/tb_uykzubjqmxbv6zkogdsd_c64962310e572f5e8a4c73a44a4fa3dd.jpg\"},{\"name\":\"name2\",
\"id\":\"134\",
\"photo\":\"\\\/gallery\\\/c9\\\/f0f8\\\/95fb\\\/c9f0f895fb98ab9159f51fd0297e236d\\\/134\\\/tb_23ffxuw9-5ys4iqtwztz_610982fa52cca03412dbc84ab0ea5e18.jpg\"}]"}
类需要一个数组,因为
List<Person> records;
最后,必须
]}
不可以,数组不是字符串,但可以尝试将记录声明为字符串并再次解析以获取数组。
]}