Android Studio:Json Parsing只加载URL中存在的50个对象中的50个

问题描述 投票:1回答:1

我写了一个从我的WordPress网站解析Json Data并将它放在ListView中的代码,一切都运行得很好,除了它决定只加载URL中存在的近50个Json对象。经过一遍又一遍的代码,在我尝试了一切之后,我会问这里可能是什么问题。

这是我的班级,叫做“getJsondata”

 public ArrayList<GamesLibrary> getJsondata(String strurl)
{
    ArrayList<GamesLibrary>arrayList=new ArrayList<GamesLibrary>();
    String line="";
    String res="";
    InputStream in=null;
    try
    {
        HttpURLConnection urlConnection=null;
        URL url = null;
        try
        {
            URL myURL = new URL(strurl);
            URLConnection ucon = myURL.openConnection();
            in = ucon.getInputStream();
            Log.d("Negev", in.toString());
        } catch (Exception e)
        {
            Log.d("asaf",e.getMessage());
        }


        BufferedReader br =new BufferedReader(new InputStreamReader(in,"iso-8859-1"));

        StringBuffer sb=new StringBuffer("");
        StringBuilder b = new StringBuilder();
        String input;

        while((input=br .readLine())!=null)
        {
            b.append(input+"\n");
        }

        in.close();
        br.close();


        try
        {
            JSONArray jArray = new JSONArray(b.toString());
            for(int i=0;i<jArray.length();i++)
            {

                Log.d("asaf","try json"+i);
                JSONObject json_data = jArray.getJSONObject(i);
                String title = json_data.getString("title");
                String content = json_data.getString("content");
                String content2 = content.replace("\\n", "");
                String content3 = Html.fromHtml(content2).toString();
                String content4 = content3.replace("\",\"protected\":false}", "");
                String title2 = title.replace("{\"rendered\"", "");
                title2 = title2.replace("\"}", "");
                title2 = title2.replace("\"", "");
                title2 = title2.replace(":", "");
                title2 = title2.replace("Date", "");
                String id = json_data.getString("id");
                String slug = json_data.getString("slug");
                GamesLibrary gamesLibrary= new GamesLibrary(Integer.valueOf(id),title2,content4,slug);
                arrayList.add(gamesLibrary);
                Log.d("ff",content3 );

            }
        }
        catch(JSONException e)
        {

        }
        return arrayList;
    }
    catch (Exception e) {
        // TODO: handle exception
    }
    return null;
}

代码运行完美,但只加载10个帖子,为什么你认为?谢谢!

更新:arraylist只包含10个对象,问题是它应该包含近50个...

更新2:确切的Json:https://docs.google.com/document/d/1wkuAFZWn1jF-_7AO_zvrI4mo1V6paUODvaUW8TAn03k/edit?usp=sharing

java android json wordpress android-studio
1个回答
1
投票

我看了你的json,它只包含10个项目:)

ids:921,919,474 472 470 468 466 464 462 460

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.