php json最大长度限制吗,php – json_encode()方法有内存限制吗?

我试图回应一个由数组组成的json编码数组,但我不知道它不会让我打印那个东西.这是我的代码:

include_once('confi.php');

header('Content-type: application/json');

if ($_SERVER['REQUEST_METHOD'] == "POST")

{

$lastRecord = isset($_POST['lastRecordID']) ?

mysql_real_escape_string($_POST['lastRecordID']) : "";

$queryForTotalRec = mysql_query("SELECT customer_id FROM `WebServiceTesting`.`sapphire` ORDER BY customer_id DESC LIMIT 1");

$total_rec = mysql_fetch_row($queryForTotalRec);

if($total_rec){

$queryForAllRecords = "SELECT * FROM `WebServiceTesting`.`sapphire` WHERE customer_ID BETWEEN %d AND %d";

$get_all_recs = mysql_query(sprintf($queryForAllRecords, $lastRecord, $total_rec[0]));

$json = array();

while($row = mysql_fetch_assoc($get_all_recs)){

$json[] = array("Status" => 1, "NewRecord" => $row);

}

print_r($json);

echo json_encode($json);

}else{

$json = array("status" => 0, "Error_Message" => mysql_error());

echo json_encode($json);

}

}else{

$json = array("status" => 0, "Error_Message" => "Request Method not correct");

echo json_encode($json);

}

@mysql_close($conn);

错误:

格式错误的JSON:意外的’A’有时’我’

当我删除print_r行时,我得到:

没有收到回复

当我打印$json数组的计数iam得到153但没有其他输出.

我试过的事情:

我读了一些解决类似问题的解决方案,你需要使用array_values()

例如:

echo json_encode(array_values($json));

同样的回答:’没有收到回复’

我也尝试将echo $json放在循环中,我知道这在概念上是错误的,但仍然得到预期的错误’语法错误’

此外,我试图回应通过foreach没有运气语法错误,但我可以看到原始输出但无法验证json.

只是对于print_r的信息,这是响应:

Array (

[0] => Array (

[Status] => 1 [NewRecord] => Array (

[customer_id] => 1241

[firstName] => Katy

[lastName] => Lest

[email] => klest@yahoo.com [phone] => 787012425

)

)

[1] => Array (

[Status] => 1 [NewRecord] => Array (

[customer_id] => 1242

[firstName] => Hanah

[lastName] => Morrisn

[email] => road@gmail.com

[phone] => 144221275 )

)

[2] => Array (

[Status] => 1 [NewRecord] => Array (

[customer_id] => 1243

[firstName] => James

[lastName] => McGrath

[email] => rosamcgrath@hotmail.com

[phone] => 79684312 )

)

)

刚刚找到了一个答案,我仍然在寻找一个理由,如果有人可以提供帮助.我拉的唱片数量是150,所以我一次尝试了50条记录并且效果很好.任何人都知道我怎样才能真正为我的阵列分配更多内存,以便它只能一次性保存所有必需的数据?

我也试过给出准确的索引以及我认为数组内存不足但这甚至不起作用:

$json = new SplFixedArray($difference);

非常感谢您的协助.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值