使用以下脚本,我返回了一个JSON数组,该数组代表数据库查询中的1000多行。
`echo "<h2>Just an array of rows...</h2>";
foreach ($query->result_array() as $row)
{
$data[] = $row;
}
var_dump(json_encode($data, TRUE));`
然而,返回的数组是单行并且在第三行之前离开屏幕,因此丢失了超过1000条记录。我需要将每个数组分开(在每个结束的大括号中分开,例如“}”)。
当前返回的JSON如下:
`'[{"Client_Desc":"Jaguar","Parent_Entity_Name":"Jaguar UK Region D","Entity_Name":"Guy Salmon Jaguar (Thames Ditton)","trackbacknumber":"8446628899","external_reference":"C8420","effective_start_date_time":"07\ /25\/2011 20:54:48","effective_end_date_time":"01\/01\/3000 00:00:00"}, {"Client_Desc":"Triumph","Parent_Entity_Name":"South","Entity_Name":"Hughenden M40 Ltd","trackbacknumber":"8446628893","external_reference":"160032","effective_start_date_time":"04\/29 \/2013 07:51:02","effective_end_date_time":"01\/'... (length=295125)`
感谢您的时间,非常感谢所有的帮助!
答案 0 :(得分:1)
Use json_decode($data, true). This will provide an associative array.
答案 1 :(得分:0)
需要将内容标题指定为json。这是通过以下方式实现的:
`header('Content-Type: application/json');`
Plus而不是var_dump,使用echo返回整个json对象。这在下面说明:
`echo(json_encode($data, TRUE));`