2017-12-31 58 views
1

WordPress 웹 사이트의 Json Data를 구문 분석하여 ListView에 넣는 코드를 작성했습니다. 은 완벽하게으로 작동합니다 URL에있는 거의 50 개 중 10 개의 Json 객체 만로드하기로 결정했습니다. 코드를 반복적으로 살펴본 후 모든 것을 시도한 후에 문제의 원인을 묻습니다.Android Studio : Json Parsing은 URL에 존재하는 50 개 중 10 개의 객체 만로드합니다.

이, 코드가 완벽하게 작동합니다 "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 개 게시물, 왜 당신은 생각합니까? 감사합니다.

는 업데이트 : 그것을 나는 당신의 JSON 보았다 https://docs.google.com/document/d/1wkuAFZWn1jF-_7AO_zvrI4mo1V6paUODvaUW8TAn03k/edit?usp=sharing

+0

URL로 이동할 때 50 개의 항목이 표시됩니까? – mmm

+0

메서드에서 10 개 항목을 반환합니까, 아니면 ListView에 10이 표시됩니까? return 문을 디버깅 할 수 있습니까? –

+0

예 URL에 50 개의 항목이 표시되며 ListView가 정상적으로 작동하므로 목록보기에 문제가 있다고 생각하지 않습니다 ... 감사합니다. – NegNeg64

답변

1

및 : 정확한 JSON : 는 ArrayList에 만 10 개체를 포함, 문제는 거의 50 ...

업데이트 2를 포함해야한다는 것입니다 단지 포함 10 개 항목 :

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

enter image description here

+0

안녕하세요 저는 정확한 Json을 게시했으며 11 번째 항목에 문제가있는 경우 어떻게해야하는지 이해하지 못했습니다. 감사합니다. – NegNeg64

+0

아, 문제가 무엇인지 찾아 냈습니다. 업데이트 된 답변을 참조하십시오. 예외는 없었습니다 :) –

+0

안녕하세요, 제 잘못, 나는 잘못된 Json을 게시했습니다! 이 사람은 10을 가지고 있다고 생각하지 않습니다 ... 아니요, 원래 하나에는 10이 하나 있습니다. 와우, 너무 바보 같은 느낌입니다. 정말 고마워요! – NegNeg64

관련 문제