2013-04-17 2 views
0

이 코드를 사용하여 Reddit에서 json 데이터를 다운로드하고 있습니다. 코드는 내가 만든 테스트 자바 프로젝트에서 작동하지만 안드로이드 장치에서 사용할 때는 그렇지 않습니다. 안드로이드 장치에서는 json 데이터의 일부만 다운로드합니다. 나는 이유를 알 수 없다. 어떤 도움을 주셔서 감사합니다.Android aynctask json

@Override 
protected JSONObject doInBackground(URL... urls) { 
    String c; 
    StringBuilder str = new StringBuilder(); 
     try { 
      BufferedReader in = new BufferedReader(new InputStreamReader((InputStream) urls[0].getContent())); 
      while((c = in.readLine()) != null) { 
       str.append(c); 
      } 
      in.close(); 
      json = new JSONObject(str.toString()); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (JSONException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    return json; 
} 
+0

오류를 찾으셨습니까? – Vinay

+0

좀 더 구체적으로 기재 할 수 있습니까? 어떤 오류가 있습니까? 데이터의 일부분을 어떻게 알았습니까? – jaga

+0

@JJPA 오류가 없습니다. –

답변

0

당신이 JSON을 구문 분석 얻기 위해 시도 할 수

public resultModel getJSONfromReddit() { 

     resultModel result = new resultModel(); 
     HttpResponse response; 
     HttpClient myClient = new DefaultHttpClient(); 
     HttpPost myConnection = new HttpPost("http://www.reddit.com/.json"); 

     try { 
      response = myClient.execute(myConnection); 
      String JSONString = EntityUtils.toString(response.getEntity(), 
        "UTF-8"); 
      JSONObject json = null; 
      json = new JSONObject(JSONString); 
      Log.i(TAG, JSONString); //this is the whole response but it'll be cutted if you only print it in the eclipse logcat 

      //PARSE YOUR JSON HERE 

     } 

     catch (Exception e) { 
      e.printStackTrace(); 
     } 

     return result; 
    } 

어쩌면 당신의 JSON은 일식 콘솔에서 cutted되는이 방법을 시도하고 마지막 데이터를 확인하기 위해 인쇄, 나는 희망을 내 대답은 충분히 명확하다 하지만 JSON 구문 분석 방법과 같은 질문에 대한 답변을 원한다면 의견을 물어보십시오.

+0

@NAYOSE 감사합니다.하지만 문제를 파악했습니다. –