【问题标题】:I want to convert below json array into array list [duplicate]我想将下面的json数组转换为数组列表[重复]
【发布时间】:2016-12-27 08:39:15
【问题描述】:

这是我的网络服务的链接,请查看 https://drive.google.com/open?id=0BwCPG2lI_UeCcXlLUGhibTJEdWs

这是 android 代码的图像 android code

请帮帮我

【问题讨论】:

  • 使用Gson,帮你轻松转换
  • 请勿发布代码图片。图像无法搜索,无法复制以进行测试,并且阻碍了可访问性。相反,将相关代码包含为formatted text
  • Gson gson=new GsonBuilder().create(); JsonArray myCustomArray = gson.toJsonTree(tag).getAsJsonArray();

标签: android arrays json


【解决方案1】:

首先您应该在JSONObject 中发送JSONArray 数据,然后通过以下代码获取并设置您的列表

    public void onResponse(String response) {
            try {
                JSONObject responseJsonObject = new JSONObject(response);

                JSONArray arrayJsonObject = responseJsonObject.getJSONArray("items");
                    for (int i = 0; i < arrayJsonObject.length(); i++) {
                        JSONObject jsonObject = arrayJsonObject.getJSONObject(i);
                        //Or do somthing with Array Datas 
                    }
                }
              }

如果你的数组没有名字:

     JSONArray jsonArray = new JSONArray(String_Result);

【讨论】:

  • 我的数组没有名字
  • 答案已编辑
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-02-16
  • 2014-06-11
  • 2012-02-08
  • 2021-09-08
  • 1970-01-01
  • 2022-07-07
  • 1970-01-01
相关资源
最近更新 更多