dongyu2047 2017-10-23 05:45
浏览 216

当JS解析时,PHP json_encode有时会丢失它的最后一个'}'括号

I'm facing an issue when use PHP json_encode function. Sometimes, the encoded JSON lost } bracket at the end of JSON, but sometimes it's not.

The PHP code:

$json = json_encode([
  'type' => 'news',
  'status' => $status, // string
  'data' => $news, // array of data
], JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);

The data contains Chinese characters. I used fetch on JS to request the JSON and when it parsed the JSON, it returned a parse error message as unexpected end of JSON input.

Here's what does the JSON looks like:
It lost <code>}</code> at the end

What's going wrong here???

  • 写回答

1条回答 默认 最新

  • dqnek0079 2017-10-23 05:59
    关注

    I am not able to add a comment here. But it seems to me, encoding is not utf-8. You can convert the encoding using mb_convert_encoding

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度