首先,最外层不是数组,是个object,不能array来解

解决方案 »

  1.   

    首先
    JSONObject aJson = new JSONObject(urlPath);
    然后
    JSONArray array = aJson.optJSONArray("Result");
    最后
    把array放进你之前那个循环里
      

  2.   

    那个Result是我自己,忘记替换了,你的应该是news
      

  3.   

    public static List<News> getListNews(String urlPath) throws Exception {
    List<News> mlists = new ArrayList<News>();
    JSONObject aJson = new JSONObject(urlPath);
    JSONArray array = aJson.optJSONArray("news");
    for (int i = 0; i < array.length(); i++) {
    JSONObject item = array.getJSONObject(i);
    String id = item.optString("id");
    String title = item.optString("title");
    String content = item.optString("content");
    String outline = item.optString("outline");
    mlists.add(new News(id, title, content, outline));
    }
    return mlists;
    }试试
      

  4.   

    Quote: 引用 7 楼 u012374885 的回复:

    public static List<News> getListNews(String urlPath) throws Exception {
    List<News> mlists = new ArrayList<News>();
    JSONObject aJson = new JSONObject(urlPath);
    JSONArray array = aJson.optJSONArray("news");
    for (int i = 0; i < array.length(); i++) {
    JSONObject item = array.getJSONObject(i);
    String id = item.optString("id");
    String title = item.optString("title");
    String content = item.optString("content");
    String outline = item.optString("outline");
    mlists.add(new News(id, title, content, outline));
    }
    return mlists;
    }又报异常 :org.json.JSONException:Value tttp of type java.lang.String cannot be converted to JSONObject
      

  5.   

    Quote: 引用 7 楼 u012374885 的回复:

    org.json.JSONException:Value tttp of type java.lang.String cannot be converted to JSONObject
    at xxxxxx  getNewsList
      

  6.   

    你的urlpath是啥?
    readparse又是啥?
      

  7.   

    public static byte[] readParse(String urlPath) throws Exception {
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    byte[] data = new byte[2048];
    int len = 0;
    URL url = new URL(urlPath);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    InputStream inStream = conn.getInputStream(); while ((len = inStream.read(data)) != -1) {
    outStream.write(data, 0, len); }
    inStream.close();
    return outStream.toByteArray(); }
    urlpath是我测试用的JSON网页 估计你打不开 我这里打开就是{"news":[{"content":"一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一","id":1,"outline":"11111111111111111111111","title":"111111111"},{"content":"二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二","id":2,"outline":"222222222222222222222222222222222222222","title":"222222222222"},{"content":"三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三","id":3,"outline":"333333333333333333333333333333333333333333333333333333333333333","title":"33333333333333"}]}
      

  8.   

    报空指针的代码
    public List<String> getData(){
    try {
    news = JsonParse.getListNews(urlPath);
    } catch (Exception e) {
    e.printStackTrace();
    }
    List<String> data = new ArrayList<String>();
    for (int i = 1; i < news.size(); i++) {
    data.add("id:"+news.get(i).getId());
        data.add("title:"+news.get(i).getTitle());
        data.add("content:"+news.get(i).getContent());
        data.add("outline:"+news.get(i).getOutline());
        
    }
    return data;
    }
      

  9.   


    urlpath不是json数据啊,我以为是json,你得先用你的readparse得到json啊,最后解的是new string(data)这个json数据
      

  10.   

    我做了TAG JSON数据已经能读出来了
    readParse(urlPath) 已经赋值给final byte[] data了
    final byte[] data = readParse(urlPath);
     JSONArray array = new JSONArray(new String(data))
    我也不知道哪出问题了 你看私信 能加QQ聊吗
      

  11.   

    public static List<News> getListNews(String urlPath) throws Exception {
        List<News> mlists = new ArrayList<News>();
        byte[] data = readParse(urlPath);
        JSONObject aJson = new JSONObject(new String(data));
        JSONArray array = aJson.optJSONArray("news");
        for (int i = 0; i < array.length(); i++) {
            JSONObject item = array.optJSONObject(i);
            String id = item.optString("id");
            String title = item.optString("title");
            String content = item.optString("content");
            String outline = item.optString("outline");
            mlists.add(new News(id, title, content, outline));
        }
        return mlists;
    }
    这样行不行