Php JSONException在的字符0处结束输入

Php JSONException在的字符0处结束输入,php,android,json,Php,Android,Json,不知何故,我的问题似乎与我可以在网上查找的问题略有不同 基本上我得到了这个错误: 10-16 12:14:03.561: E/log_tag(1271): org.json.JSONException: End of input at character 0 of 在Eclipse上尝试从Android仿真器检索php脚本执行的以下JSON结果时:[{“id”:“3”}] 从我所读到的内容来看,我的问题意味着我的php脚本(在我的浏览器btw中运行良好)的JSON结果是空的,但这是怎么回事

不知何故,我的问题似乎与我可以在网上查找的问题略有不同

基本上我得到了这个错误:

10-16 12:14:03.561: E/log_tag(1271): org.json.JSONException: End of input at character 0 of 
在Eclipse上尝试从Android仿真器检索php脚本执行的以下JSON结果时:
[{“id”:“3”}]

从我所读到的内容来看,我的问题意味着我的php脚本(在我的浏览器btw中运行良好)的JSON结果是空的,但这是怎么回事

以下是我的MainActivity类的代码:

protected Void doInBackground(String... params) {

    //InputStream isr = null;

    // Connect to Database + Webserver
    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(
                "http://10.0.2.2:8080/php/AndroidTest.php"); // My php script adress                                                                    
        httppost.setHeader("Content-Type", "application/json");
        httppost.setHeader("Accept", "JSON");                                                       
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();

        int status = response.getStatusLine().getStatusCode();

        if(status== HttpStatus.SC_OK){
            jsonString = EntityUtils.toString(entity);
        }

        //isr = entity.getContent();
    } catch (Exception e) {
        // TODO: handle exception
        Log.e("log_tag", "Error Connecting to Database/Webserver: " + e.toString());
    }

    //Parse JSON data   
    try {
        String s = "";
        JSONObject jsonObject = new JSONObject(jsonString);
        JSONArray jArray = jsonObject.getJSONArray("id");

        for (int i = 0; i < jArray.length(); i++) {
            //JSONArray jArray = jArray.getJSONArray("id");
            JSONObject json = jArray.getJSONObject(i);
            s = s + "ID: " + json.getString("id");
        }
        finalResult = s;

    } catch (Exception e) {
        // TODO: handle exception
        Log.e("log_tag", "Error Parsing JSON Data: " + e.toString());
    }

    return null;
}

protected void onPostExecute(String result) {
    //MainActivity.resultView.setText("Ergebnis: " + sResult);
    MainActivity.resultView.setText(finalResult);
}
protectedvoiddoinbackground(字符串…参数){
//InputStream isr=null;
//连接到数据库+Web服务器
试一试{
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(
"http://10.0.2.2:8080/php/AndroidTest.php“”;//我的php脚本地址
setHeader(“内容类型”、“应用程序/json”);
setHeader(“接受”、“JSON”);
HttpResponse response=httpclient.execute(httppost);
HttpEntity=response.getEntity();
int status=response.getStatusLine().getStatusCode();
if(status==HttpStatus.SC\u OK){
jsonString=EntityUtils.toString(实体);
}
//isr=entity.getContent();
}捕获(例外e){
//TODO:处理异常
Log.e(“Log_标记”,“连接到数据库/Web服务器时出错:”+e.toString());
}
//解析JSON数据
试一试{
字符串s=“”;
JSONObject JSONObject=新的JSONObject(jsonString);
JSONArray jArray=jsonObject.getJSONArray(“id”);
for(int i=0;i
php脚本:

<?php

$con = mysql_connect("localhost","root","mcf");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}
mysql_select_db("mcf", $con);

$result = mysql_query("SELECT id FROM Fragensatz1");

while($row = mysql_fetch_assoc($result))
{
    $output[]=$row;
}

print(json_encode($output));

mysql_close($con);

?>

好的,我找到了问题所在: 1.我通过XAMPP运行Apache Web服务器,但也有一台Tomcat服务器在运行 2.本地主机地址没有使用正确的端口,我应该使用80而不是8080


感谢您的支持和想法

你不应该在这里粘贴你的密码!请记住,自PHP5.5以来,
mysql.*
函数已被弃用。你应该改为使用PDO我们的MySQLi。顺便说一句,我不能查看。当然你不能,这是一个本地主机地址:P,关于MySQL与Android的联系,我被告知不同。我在本地模拟器上运行代码,顺便说一句,这就是我使用该地址的原因,它只是告诉模拟器连接到在我的PC上运行的本地Web服务器。哦,我没有意识到这一点,因为我习惯了
192.168.
地址。你的MySQL没有连接到Android,只是PHP连接到你的MySQL服务器。是的,这就是我想说的,你猜怎么了吗?