1

このjsonがAndroidで機能しない理由を誰かが知っていますか? urlJson

結果は 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();
        }
4

3 に答える 3

1

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);
于 2012-08-16T10:55:10.973 に答える
0

形式が間違っています。{"name": "string"、 "...":"..."}を使用します

于 2012-08-16T10:00:05.930 に答える
0

問題は解決しました。私は春を使用していて、サービスでこれを削除しました

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

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

今すぐ動作します!

于 2012-08-16T11:26:13.363 に答える