您正在尝试解码无效的JSON字符串错误

时间:2018-05-18 14:07:33

标签: php sql-server extjs sencha-architect

我正在尝试使用GridSQL来源输出PHP,但它不起作用。

这是我在控制台中遇到的错误:

[W] For WAI-ARIA compliance, IMG elements SHOULD have an alt attribute.
[E] Ext.JSON.decode(): You're trying to decode an invalid JSON String: 
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: id in C:\wamp64\www\EmployeeMenu\_data\employee\Read_employee.php on line <i>14</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0019</td><td bgcolor='#eeeeec' align='right'>242280</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp64\www\EmployeeMenu\_data\employee\Read_employee.php' bgcolor='#eeeeec'>...\Read_employee.php<b>:</b>0</td></tr>
</table></font>
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: id in C:\wamp64\www\EmployeeMenu\_data\employee\Read_employee.php on line <i>14</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0019</td><td bgcolor='#eeeeec' align='right'>242280</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp64\www\EmployeeMenu\_data\employee\Read_employee.php' bgcolor='#eeeeec'>...\Read_employee.php<b>:</b>0</td></tr>
</table></font>
[{"id":null,"firstname":"Alain","lastname":"Doyon","title":"Project Manager","businessunit":"Dev","experience":"7"},{"id":null,"firstname":"Joel","lastname":"Deslauriers","title":"Integrator Senior","businessunit":"Kappa","experience":"5"}]

这是我的PHP文件:

<?php
require_once"..//..//_includes/headers.php";



$query = "select firstname, lastname, title, businessunit, experience from 
employee_tab order by businessunit";
logit($query);
$result = odbc_exec($connection,$query);
$cnt = 0;
while($row = odbc_fetch_array($result))

{ 
$cnt = $cnt + 1;
$myArray[] = array(
    'id'=>$row['id'],
    'firstname'=>$row['firstname'],
    'lastname'=>$row['lastname'],
    'title'=>$row['title'],
    'businessunit'=>$row['businessunit'],
    'experience'=>$row['experience'],
    );


}

if (isset($myArray))
{
    if ( sizeof($myArray) > 0 )
    {
        $output = json_encode($myArray);
        echo $output;
    }
    else
    {
        echo '(success:true,"error":0)';    
    }
}
else
    {
        echo '(success:true,"error":0)';
    }

?>

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

你得到这个是因为你已经开启了display_errors,因此会收到有关事情的警告,从而破坏你的JSON。

在php.ini中关闭它

最佳的错误记录体验是将终端中的日志拖尾,而不会在屏幕上显示。

对第14行的Read_employee.php进行isset()检查以获取开始!祝你好运

答案 1 :(得分:1)

该消息是自我解释:Notice: Undefined index: id in C:\wamp64\www\EmployeeMenu\_data\employee\Read_employee.php on line <i>14</i>

您的$查询请求将仅返回&#34;名字,姓氏,职位,商家单位,经验&#34;列,而不是&#34; id&#34; ,但你在while循环中使用[&#39; id&#39;]。和paf,警告!