我从Web服务获得以下字符串的JSON,并尝试将其转换为 JSONarray
{
"locations": [
{
"lat": "23.053",
"long": "72.629",
"location": "ABC",
"address": "DEF",
"city": "Ahmedabad",
"state": "Gujrat",
"phonenumber": "1234567"
},
{
"lat": "23.053",
"long": "72.629",
"location": "ABC",
"address": "DEF",
"city": "Ahmedabad",
"state": "Gujrat",
"phonenumber": "1234567"
},
{
"lat": "23.053",
"long": "72.629",
"location": "ABC",
"address": "DEF",
"city": "Ahmedabad",
"state": "Gujrat",
"phonenumber": "1234567"
},
{
"lat": "23.053",
"long": "72.629",
"location": "ABC",
"address": "DEF",
"city": "Ahmedabad",
"state": "Gujrat",
"phonenumber": "1234567"
},
{
"lat": "23.053",
"long": "72.629",
"location": "ABC",
"address": "DEF",
"city": "Ahmedabad", …Run Code Online (Sandbox Code Playgroud) 我想解析JSON数组并使用gson.首先,我可以记录JSON输出,服务器明确地响应客户端.
这是我的JSON输出:
[
{
id : '1',
title: 'sample title',
....
},
{
id : '2',
title: 'sample title',
....
},
...
]
Run Code Online (Sandbox Code Playgroud)
我试过这个结构进行解析.一个类,它依赖于单个array和ArrayList所有JSONArray.
public class PostEntity {
private ArrayList<Post> postList = new ArrayList<Post>();
public List<Post> getPostList() {
return postList;
}
public void setPostList(List<Post> postList) {
this.postList = (ArrayList<Post>)postList;
}
}
Run Code Online (Sandbox Code Playgroud)
发布课程:
public class Post {
private String id;
private String title;
/* getters & setters */
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用gson没有错误,没有警告和没有日志:
GsonBuilder gsonb = new GsonBuilder();
Gson gson …Run Code Online (Sandbox Code Playgroud)