如何在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"
}
}
}