小编itt*_*hie的帖子

Android以及如何将字符串对象更改为json对象

我试图从我的服务器使用restful服务获得响应,我以json格式返回,更改为字符串变量然后我尝试从字符串变量更改为json对象,但我收到错误这里是我的类在我的类是我的堆栈跟踪然后我的字符串变量之后,当我尝试从字符串转换为json对象时发生错误,感谢您的帮助:

private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... urls) {
            String response = "";
            for (String url : urls) {
                DefaultHttpClient client = new DefaultHttpClient();
                HttpGet httpGet = new HttpGet(url);
                try {
                    HttpResponse execute = client.execute(httpGet);
                    InputStream content = execute.getEntity().getContent();

                    BufferedReader buffer = new BufferedReader(
                            new InputStreamReader(content));
                    String s = "";
                    while ((s = buffer.readLine()) != null) {
                        response += s;
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            try {
                //JSONObject json = …
Run Code Online (Sandbox Code Playgroud)

rest android json

2
推荐指数
1
解决办法
2208
查看次数

标签 统计

android ×1

json ×1

rest ×1