dqlk31541 2018-04-24 10:06
浏览 141

php json_encode有时返回0,零值[重复]

This question already has an answer here:

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.

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?

Here is a code snippet:

$jsonPayload = [];

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

return json_encode($jsonPayload);
</div>
  • 写回答

1条回答 默认 最新

  • dongxiaoxing3058 2018-04-24 10:19
    关注

    use

    json_encode($jsonPayload,JSON_UNESCAPED_SLASHES);
    

    Probably it will work.

    评论

报告相同问题?

悬赏问题

  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程