Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.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
PHP MySQL JSON:错误为:Token';对象的开始';在最外层数组或对象之后不应出现_Php_Mysql_Json - Fatal编程技术网

PHP MySQL JSON:错误为:Token';对象的开始';在最外层数组或对象之后不应出现

PHP MySQL JSON:错误为:Token';对象的开始';在最外层数组或对象之后不应出现,php,mysql,json,Php,Mysql,Json,我已经创建了一个php,它在MySQL数据库上执行Select*来返回iOS应用程序中使用的数据。我无法正确解析JSON,并收到错误:“最外层数组或对象后不应出现标记‘对象的开始’以及错误:“结束时的垃圾”。我是PHP的初学者,不知道是否有人能提供一些见解?谢谢大家! <?php error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); $dbhost = "xxxxxxxxxx.xxxxxx.com"; $dbuser = "xxxxxxx

我已经创建了一个php,它在MySQL数据库上执行Select*来返回iOS应用程序中使用的数据。我无法正确解析JSON,并收到错误:“最外层数组或对象后不应出现标记‘对象的开始’以及错误:“结束时的垃圾”。我是PHP的初学者,不知道是否有人能提供一些见解?谢谢大家!

 <?php
 error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);

 $dbhost = "xxxxxxxxxx.xxxxxx.com";

 $dbuser = "xxxxxxx";
 $dbpass = "xxxxxx";
 //database name
 $dbdb = "xxxxx";

 //connect to mySQL
 $connect = mysql_connect($dbhost, $dbuser, $dbpass)
 or die ("connection error");

 //select database
 mysql_select_db($dbdb) or die ("database selection error"); // line 20

 //query the table android meal
 $query = mysql_query ("SELECT * FROM ScheduleDayOne");

 //create a while loop that places the returned data into an array
 while ($list = mysql_fetch_assoc($query)){

 //store the returned data into a variable
 $output = $list;

 //encode the returned data in JSON format
 echo json_encode($output);

 }
 //close connection
 mysql_close();

 ?>

您在未正确分离的情况下回显多个对象:

... son","speaker3":"Kenner"}{"id":"b1","session":"Ge ...
----------------------------^
可以将它们包装到数组中:

[{... son","speaker3":"Kenner"}, {"id":"b1","session":"Ge ...}]
^------------------------------^------------------------------^
编辑:

要在PHP中实现这一点,可以执行以下操作:

...
$output = array();

while ($list = mysql_fetch_assoc($query)){
    $output[] = $list;
}

echo json_encode($output);
...
...
$output = array();

while ($list = mysql_fetch_assoc($query)){
    $output[] = $list;
}

echo json_encode($output);
...