从 json 文件解析数组时,图像不会显示。里面的值JSONArray school2 = school.getJSONArray("contains");
不显示在屏幕上,我使用的是正确的方法吗?
我正在调试此阶段显示的值:Category_name.add(object.getString("name"));
调试告诉我有必要为数组中的每个元素提供 id。
{
"status":1,
"message":"",
"data":
{
"entree":
{
"id":32,
"name":"Cheese Burger",
"description":"Lorem ipsum d dolore.",
"image":"http:\/\/198.57.208.46\/~school\/images\/android\/cheese-burger.png",
"contains":
[
{
"name":"Cheese",
"image":"http:\/\/198.57.208.46\/~school\/images\/android\/cheese1.png"
},
{
"name":"Tomato",
"image":"http:\/\/198.57.208.46\/~school\/images\/android\/tomato.png"
},
{
"name":"Bread",
"image":"http:\/\/198.57.208.46\/~school\/images\/android\/bread.png"
}
],
"nutritions":
{
"Calories":"150",
"Carbohidrates":"16g"
}
}
}
JSONObject json = new JSONObject(str);
JSONObject json2 = new JSONObject(str);
message = json2.getString("message");
status = json2.getString("status");
if (status.equals("1")) {
JSONObject data = json.getJSONObject("data");
JSONObject school = data.getJSONObject("entree");
txt1.setText(school.getString("name"));
// txt2.setText(school.getString("name"));
txt3.setText(school.getString("description"));
String url1 = school.getString("image");
imgLoader.DisplayImage(url1, img1);
JSONArray school2 = school.getJSONArray("contains");
for (int i = 0; i < school.length(); i++) {
JSONObject object = school2.getJSONObject(i);
\\Category_ID.add(Long.parseLong(object.getString("id")));
Category_name.add(object.getString("name"));
Category_image.add(object.getString("image"));
listview.setAdapter(cla);
}
}