Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.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
json jquery格式问题_Jquery_Json - Fatal编程技术网

json jquery格式问题

json jquery格式问题,jquery,json,Jquery,Json,这是我在服务器端的代码 $results = array(); while($rw = $objS->row($rs)) { $results[]=array('id'=>$rw["id"], 'agent_id'=>$rw["agent_id"], 'agent'=>$rw["agent"]); } echo json_encode($results); 在客户端,我有这样的编码 success: function( data ) { var forum = dat

这是我在服务器端的代码

$results = array();
while($rw = $objS->row($rs))
 {
$results[]=array('id'=>$rw["id"],
'agent_id'=>$rw["agent_id"],
'agent'=>$rw["agent"]);
}
echo json_encode($results);
在客户端,我有这样的编码

success: function( data ) {
var forum = data.results;
for(i = 0, l = forum.length; i < l; i++) {
row = forum[i];
alert(row.id);
}
我需要这样

{"results":[{"id":1,"agent_id":"888","agent":"Emili"}]}
您的
array()
声明完全错误。。试试这个

要填充多个记录值,意味着

<?php
    while($rw = $objS->row($rs))
     {
       $results[] = $rw;         // It generate Array of Array
     }

   $agentResult['results']  = $results;

   $jsonResult = json_encode($agentResult);
  echo $jsonResult;
?>


您需要它,因为客户端代码访问
数据。结果
。也许你可以写
var论坛=数据取而代之,或者直接使用
数据
?警报(数据)给我[object object],[object object]是的,它是两个对象的数组,与
数据相同。如果服务器端代码生成
结果
对象,则结果
会给你。尝试直接使用
数据
而不是在循环中使用
论坛
。@user2244804:您说过,问题只来自
服务器端
,那么在
客户端脚本
上讨论的原因是什么。。还有什么问题吗?先生,这也不起作用了…先生,如何像这样创建它…{“results”:[{“id”:1,“agent_id”:“888”,“agent”:“Emili”}}}这很好,但我想在while循环中添加另一个查询,并获得一些值,还想传入结果数组。。
<?php
    while($rw = $objS->row($rs))
     {
       $results[] = $rw;         // It generate Array of Array
     }

   $agentResult['results']  = $results;

   $jsonResult = json_encode($agentResult);
  echo $jsonResult;
?>