使用JsonObject解析JsonArray?

时间:2017-11-28 12:19:22

标签: java android json

你好如何从另一个Json数组中的Json数据获取数据我已经获取数据直到附件但附件不起作用,我仍然在行代码上得到错误

的java

   private void parseJsonFeed(JSONObject response) {
        try {
            JSONArray feedArray = response.getJSONArray("items");
            for (int i = 0; i < feedArray.length(); i++) {
                JSONObject post = (JSONObject) feedArray.get(i);
                PostItem searchItem = new PostItem();
                searchItem.setId(post.getString("id"));
                searchItem.setName(post.getString("title"));
                searchItem.setDescription(Utils.getSummaryFromHTML(post.getString("content"), 140));

                searchItem.setContent(post.getString("content"));
                if (response.has("images")) {
                    searchItem.setImage(response.getJSONObject("images").getString("url"));
                } else {
                    searchItem.setImage(Utils.getFirstImage(post.getString("content"), Boolean.valueOf(false)));
                }

                searchItem.setTimeStamp(post.getString("updated"));
                if (post.has("labels")) {
                    JSONArray labels = post.getJSONArray("labels");
                    List<String> cat = new ArrayList();
                    for (int ix = 0; ix < labels.length(); ix++) {
                        cat.add(labels.getString(ix));
                    }
                    searchItem.setCategory(Utils.join(cat, ","));
                }
                searchItem.setUrl(post.getString("url"));
                this.feedItems.add(searchItem);
            }
            this.listView.setVisibility(View.VISIBLE);
            this.listAdapter.notifyDataSetChanged();
            this.isLoadingProgress = false;
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

错误行

  

PostItem searchItem = new PostItem();

error line

谢谢

0 个答案:

没有答案