如何将json数组解析为listview

时间:2015-03-27 06:22:35

标签: android json

朋友我试图将json数据放入列表视图但我没有得到它,我从json中获取数据它显示在log cat中请帮助我。

                JSONArray jarray = new JSONArray(data);

                for (int i = 0; i < jarray.length(); i++) {
                    JSONObject object = jarray.getJSONObject(i);

                    Actors actor = new Actors();


                    JSONObject author = object.getJSONObject("author");
                     String authorName = author.getString("name");
                     Log.d("All Products: ", authorName.toString());
                     String avatar = author.getString("avatar");
                     Log.d("All Products: ", avatar.toString());

                     JSONArray author1 = object.getJSONArray("bm_property_owner_email");
                     // new code embedded
                    //actor.setAuthor(jRealObject.getString("bm_property_owner_email"));
                    //actorsList.add(actor);
                     Log.d("bm_property_owner_email: ", author1.toString());

                      JSONObject links = object.getJSONObject("meta").getJSONObject("links");
                       String collectionLink = links.getString("collection");
                      Log.d("Content: ", collectionLink.toString());

2 个答案:

答案 0 :(得分:0)

试试这个

String id = response.getString("ID");
String title = response.getString("title");

JSONArray jsonArray = response.getJSONArray("author");
Actors actor = new Actors();
actot.setID(jsonArray.getJSONObject(0).getString(
                                            "ID"));
actor.setUserName(jsonArray.getJSONObject(0).getString(
                                            "username"));
actor.setName(jsonArray.getJSONObject(0).getString(
                                            "name"));
JSONArray insideJsonArray = jsonArray.getJSONObject(0)                                                      .getJSONArray("meta");
for (int i = 0; i < insideJsonArray.length(); i++) {
    JSONObject object = jsonArray.getJSONObject(i);
    JSONArray array = object.getJSONArray("links");
    for (int j = 0; j < array.length(); j++) {
      JSONObject jObject = array.getJSONObject(j);
      String self = jObject.getString("self");
      String archives = jObject.getString("archives");
    }        
}

答案 1 :(得分:0)

您需要将JSONArray传递给&#34;自定义适配器&#34;在getView函数中,您可以创建列表行视图。

您甚至可以创建Java对象列表并将其传递给自定义适配器。

互联网上有足够的示例可帮助您创建自定义适配器。