php json_encode 有时返回 0 ,零值 [英] php json_encode is returning 0 , zero value sometimes

查看:73
本文介绍了php json_encode 有时返回 0 ,零值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出了点问题,我将 json_encode 响应保存在 mysql 数据库中.它有时会保存 0 value.im 100% 确定我的 json_encode 函数不会接收 0 作为参数,因为它总是得到空数组或关联数组,所以没有任何有机会在参数中接收0.

something is going wrong , im saving json_encode response in mysql db. it sometimes saving 0 value.im 100% sure that my json_encode function does not receive 0 as a parameter because it always get empty array or associated array, so there is no any chance to receive 0 in parameter.

问题是有时 json_encode 返回 0 值的原因.我在 db 表中有列类型 longtext ,我保存了它的响应.是字符类型的问题吗?像UTF8还是非UTF8?

Problem is that why json_encode returns 0 value sometimes. i have column type longtext in db table where im saving its response. is it issue with character types? like UTF8 or non UTF8?

这是一个代码片段:

$jsonPayload = [];

if (isset($obj['answer']) && (!empty($obj['answer']) || $obj['answer'] == 0)) {
       $jsonPayload[$form_fields[$i]->id] = $obj;         
}

return json_encode($jsonPayload);

推荐答案

使用

json_encode($jsonPayload,JSON_UNESCAPED_SLASHES);

可能会奏效.

这篇关于php json_encode 有时返回 0 ,零值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆