【问题标题】:How to parse this JSON Array in android如何在android中解析这个JSON数组
【发布时间】:2012-03-02 07:29:30
【问题描述】:

我想要每个 TAG 的名称、电子邮件和图像。我必须在列表元素中显示。

{
   "response":[
      {
         "name":"Brajendra Mishra",
         "email":"test1@seologistics.com",
         "address":"Information Service\r\nParliament of Canada\r\nOttawa, Ontario K1A 0A9",
         "aboutus":"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. ",
         "image":"http:\/\/74.52.209.213\/lab\/event\/img\/attachments\/photos\/small\/4f2a5a71-acc0-4319-b1ca-14774a34d1d5.jpg"
      },
      {
         "name":"Toney Grey",
         "email":"test2@seologistics.com",
         "address":"Information Service\r\nParliament of Canada\r\nOttawa, Ontario K1A 0A9",
         "aboutus":"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. ",
         "image":"http:\/\/74.52.209.213\/lab\/event\/img\/attachments\/photos\/small\/4f1d4283-5204-4f16-90d6-69924a34d1d5.jpg"
      }
   ],
   "count":2
}

我尝试了很多但做不到。

让我知道循环,如何达到每个名称、电子邮件、图像等的值,如何保持。

【问题讨论】:

  • 对不起,伙计,我们需要更多信息。第一段 JSON 是什么,第二段是什么?另外,您没有使用 JSONObject 吗?你在使用 ArrayLists 吗?
  • 感谢您的快速回复。给我一些时间,我给你更多信息。

标签: android json parsing


【解决方案1】:

我为你的用户生成了一个解决方案。

JSONArray jObject = new JSONArray(jsoninputstring);
        for (int i = 0; i < jObject.length(); i++,start++) {
             JSONObject menuObject = jObject.getJSONObject(i);

             String name= menuObject.getString("name");
             String email= menuObject.getString("email");
             String image= menuObject.getString("image");
        }

【讨论】:

  • 什么是“start++”爵士乐?
【解决方案2】:

这样试试

jObj 是您从服务器获得的响应。

try { 
        JSONObject get_string = new JSONObject(jObj.toString()); 

        jsonProduct_jsonarray = new JSONArray();

        jsonProduct_jsonarray = get_string .getJSONArray("response");

        // Receive the JSON object from server
        for (int i = 0; i < jsonProduct_jsonarray.length(); i++) {

            System.out.println("GOT JSON VALUE ");
            JSONObject c = jsonProduct_jsonarray.getJSONObject(i);

            String name= c.getString("name");
            String  email= c.getString("email");
            String  address= c.getString("address");
            String  aboutus= c.getString("aboutus");
            String   image= c.getString("image"); 
        }

转到working example, this might help you out

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 2019-12-27
    • 1970-01-01
    相关资源
    最近更新 更多