2012-08-15 3 views
1

누군가가 왜 안드로이드 에서이 json 작동하지 알아? urlJsonAndroid에서 webservice Rest에서 Json을 읽는 중입니다. FileNotFoundException

결과는 FileNotFoundException이지만 탐색기에서 작동합니다.

편집 :

public static String readUrl(String urlString) throws Exception { 
     BufferedReader reader = null; 

     try{ 
      URL url = new URL(urlString); 
      reader = new BufferedReader(new InputStreamReader (url.openStream())); 
      StringBuffer buffer = new StringBuffer(); 
      int read; 
      char[]chars = new char[1024]; 
      while ((read = reader.read(chars)) != -1) 
       buffer.append(chars, 0, read); 

      return buffer.toString(); 
     } finally { 
      if (reader != null) 
       reader.close(); 
     } 
+0

에는 코드가 포함되어 있습니다. –

답변

1

Use BufferedReader는이 작업을 수행하는 가장 좋은 방법은 아닙니다. org.json. * 라이브러리를 사용하는 다음 샘플을 사용하면 HttpClient를 더 잘 사용할 수 있습니다.

HttpClient httpClient = new DefaultHttpClient(); 

    HttpPost post = new HttpPost("http://www.*****.com/json"); 

     // Execute HTTP Post Request 
     HttpResponse response = httpClient.execute(post); 
     String respStr = EntityUtils.toString(response.getEntity()); 

     JSONArray respJSON = new JSONArray(respStr); 
0

형식이 잘못되었습니다. { "name": "string", "...": "..."} 사용

0

문제는, 내가 봄 사용하고 해결 나는

@RequestMapping(value="/categorias", method = RequestMethod.GET) 
    public @ResponseBody Portada getCategorias() { 

이제 작동에 서비스

@RequestMapping(value="/categorias", method = RequestMethod.GET,headers="Accept=application/json") 
    public @ResponseBody Portada getCategorias() { 

이 제거!

관련 문제