相关疑难解决方法(0)

将字符串转换为JSON数组

我从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)

java android json

75
推荐指数
5
解决办法
36万
查看次数

如何使用Gson解析JSON数组

我想解析JSON数组并使用gson.首先,我可以记录JSON输出,服务器明确地响应客户端.

这是我的JSON输出:

 [
      {
           id : '1',
           title: 'sample title',
           ....
      },
      {
           id : '2',
           title: 'sample title',
           ....
     },
      ...
 ]
Run Code Online (Sandbox Code Playgroud)

我试过这个结构进行解析.一个类,它依赖于单个arrayArrayList所有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)

java arrays android json gson

73
推荐指数
3
解决办法
10万
查看次数

标签 统计

android ×2

java ×2

json ×2

arrays ×1

gson ×1