Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android的webservice Rest中读取Json。FileNotFoundException_Android_Json_Web Services_Rest_Filenotfoundexception - Fatal编程技术网

在Android的webservice Rest中读取Json。FileNotFoundException

在Android的webservice Rest中读取Json。FileNotFoundException,android,json,web-services,rest,filenotfoundexception,Android,Json,Web Services,Rest,Filenotfoundexception,有人知道为什么不在android中使用json吗 结果是FileNotFoundException,但在导航器上工作 编辑: public static String readUrl(String urlString) throws Exception { BufferedReader reader = null; try{ URL url = new URL(urlString); reader = new Bu

有人知道为什么不在android中使用json吗

结果是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();
        }
格式错误。 使用{“name”:“string”,“…:”}

格式错误。
使用{“name”:“string”,“…:”}

使用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);

使用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);

问题解决了,我正在使用spring,我在服务中删除了它

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


现在开始工作了

问题解决了,我正在使用spring,并在服务中删除了它

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

现在开始工作了