-4

如何在textview中添加json数组?我想在文本视图中显示 json 数组对象“名称”。我该怎么做?如何在数组中获取单个元素?我想在 textview 中打印 json 数组对象名称

        JSONObject json2 = new JSONObject(str);

        status = json2.getString("status");
        if (status.equals("1")) {       


        JSONArray school2 = json2.getJSONArray("data");

                        txt1.setText(data2.getString("name"));
                             }



 "status":1,
 "data":
  [
  {
  "dish_id":"37",
  "name":"dish2",
  "description":"testing",

  "allergen":
  "Eggs3,walnuts",
  "image":"http:\/\/198.57.208.46\/~school\/uploads\/images\/dishes\/egg-biryani.jpg",
  "ingredient":"weqweqw23,dsfds"
  }
   ],

 "dish_nutrition":
 {"1":
    {
     "name":"Cholesterol and Diet",
     "qty":"2"
  },"2":
 {
    "name":"Cholesterol and Diet",
    "qty":"1"
 }
 }
 }
4

1 回答 1

0

您可以像这样访问该字段:

school2.getJSONObject(0).getString("name")

有关详细信息,请在文档中查找

于 2013-08-28T11:31:54.147 回答