Java 将HttpClient响应转换为JsonObject时出错

Java 将HttpClient响应转换为JsonObject时出错,java,php,android,mysql,json,Java,Php,Android,Mysql,Json,我正在从事一个Android项目,我正在让我的Android应用程序发布到一个PHP REST web服务,然后该web服务返回JSON供Android应用程序处理 该应用程序所做的是允许用户从他们的android应用程序管理MySQL数据库,因此我在数据库上运行查询并返回JSON,但我得到一个JSON异常。下面是我用来发布到服务器并获取响应的代码 new Thread(new Runnable() { @Override

我正在从事一个Android项目,我正在让我的Android应用程序发布到一个PHP REST web服务,然后该web服务返回JSON供Android应用程序处理

该应用程序所做的是允许用户从他们的android应用程序管理MySQL数据库,因此我在数据库上运行查询并返回JSON,但我得到一个JSON异常。下面是我用来发布到服务器并获取响应的代码

    new Thread(new Runnable() {

                @Override
                public void run() {
                    try
                    {
                        HttpClient httpClient = new DefaultHttpClient();
                        HttpPost httpPost = new HttpPost(serverUrl);
                        if (postData != null)
                        {
                            httpPost.setEntity(new UrlEncodedFormEntity(postData));
                        }

                        ResponseHandler<String> responseHandler = new BasicResponseHandler();

                        String responseBody = httpClient.execute(httpPost, responseHandler);

                        Log.d(TAG + " Response", responseBody);

                        ServerResultProcessor serverResultProcessor = new ServerResultProcessor(progressDlg);
serverResultProcessor.processExecuteSqlQuery(iQueryExecution, 
                                new JSONObject(responseBody));
下面是从logcat返回的JSON

12-16 00:33:41.106:D/PostToApi回复(8513):[{“0”:“1”,“id”:“1”,“1”:“1”,“SoftwareID”:“1”,“2”:“1”,“PlatformID”:“1”,“3”:“6.0.1.8”,“版本”:“6.0.1.8”},{“0”:“2”,“id”:“2”,“1”,“SoftwareID”:“1”,“2”:“1”,“PlatformID”:“1”,“1”,“3”:“6.0.1.9”,“版本”:“6.0”:“3”,“id”:“1”,“1”,“1”,“PlatformID”:“1”,“0.1”,“1”,“0.1”:“0”:“1”::“6.0.2.0”},{“0”:“4”,“id”:“4”,“1”:“1”,“SoftwareID”:“1”,“2”:“1”,“PlatformID”:“1”,“3”:“6.0.2.1”,“版本”:“6.0.2.1”},{“0”:“5”,“id”:“5”,“1”:“1”,“SoftwareID”:“1”,“2”:“1”,“PlatformID”:“1”,“3”:“6.1.0.0”,“版本”:“6.1.0.0”}]

以下是例外情况:

13.3.1.1.3.3,“”3“,3”、“1”,“1”,“1”,“1”,“1”,“0”1”,“0”1”,“1”,“0”1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“3”,“3”,“3”,“3”,“3”,“3”,“3”,“2”,“2”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“0”1”,“1”,“0”1”,“0”,“0”2”,“2”,“2”,“2”,“2”,“2”,“2”,“1”,“2”,“2”,“2”,“2”,“2”,“2”,“2”,“3”,“3”,“3”,“3”,“3”,“3”,“3”,“3”,“3”,“1”,“3”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“1”,“0”,“1”,“0”,“1”,“1”,“0”,“0”,“0,“版本”:“6.0.2.0”、“SoftwareID”:“1”}、{“3”:“6.0.2.1”、“id”:“4”、“2”:“1”、“0”:“1”、“平台化”:“1”、“版本”:“6.0.2.1”、“SoftwareID”:“1”}、{“3”:“6.1.0.0”、“id”:“5”、“2”:“1”、“1”:“1”、“0”:“5”、“平台化”:“1”、“版本”:“6.1.0.0”、“SoftwareID”:“1”}


我看不出这有什么问题。

问题是您的JSON

[{"0":"1","id":"1","1":"1","SoftwareID":"1","2":"1","PlatformID":"1","3":"6.0.1.8","Version":"6.0.1.8"},{"0":"2","id":"2","1":"1","SoftwareID":"1","2":"1","PlatformID":"1","3":"6.0.1.9","Version":"6.0.1.9"},{"0":"3","id":"3","1":"1","SoftwareID":"1","2":"1","PlatformID":"1","3":"6.0.2.0","Version":"6.0.2.0"},{"0":"4","id":"4","1":"1","SoftwareID":"1","2":"1","PlatformID":"1","3":"6.0.2.1","Version":"6.0.2.1"},{"0":"5","id":"5","1":"1","SoftwareID":"1","2":"1","PlatformID":"1","3":"6.1.0.0","Version":"6.1.0.0"}]
是一个数组(注意前面的
[
),您正试图将其用作JSON对象

使用


例外情况是什么?抱歉,如果我把它包括进来,会有帮助的,它似乎没有提供那么多帮助,尽管错误告诉您问题的确切原因…响应是一个JSON数组,而不是JSON对象。感谢似乎很明显now@Boardy不客气。记住。熟悉他们,你不应该有任何进一步的机会她的问题。
[{"0":"1","id":"1","1":"1","SoftwareID":"1","2":"1","PlatformID":"1","3":"6.0.1.8","Version":"6.0.1.8"},{"0":"2","id":"2","1":"1","SoftwareID":"1","2":"1","PlatformID":"1","3":"6.0.1.9","Version":"6.0.1.9"},{"0":"3","id":"3","1":"1","SoftwareID":"1","2":"1","PlatformID":"1","3":"6.0.2.0","Version":"6.0.2.0"},{"0":"4","id":"4","1":"1","SoftwareID":"1","2":"1","PlatformID":"1","3":"6.0.2.1","Version":"6.0.2.1"},{"0":"5","id":"5","1":"1","SoftwareID":"1","2":"1","PlatformID":"1","3":"6.1.0.0","Version":"6.1.0.0"}]
new JSONArray(responseBody);