dongmu5596 2019-08-13 05:38
浏览 382

PHP编码错误json_encode()错误[关闭]

I am running below code in PHP:

error_reporting(E_ERROR | E_PARSE);
header("Content-Type:application/json");
$version = GetFileVersion("../XXXXXXXXXX.exe");
$response = new \stdClass();
$response->version = $version;
$response = json_encode($response);
echo $response;
exit();

at URL: XXXXXXXXXXXXXXX

But I get:

{"version":"2\u00000\u00001\u00009\u0000.\u00007\u0000.\u00002\u00000"}

while I am expecting:

{ "version":"2019.7.20 }

What am I doing wrong?

GetFileVersion is defined here:

https://stackoverflow.com/questions/2029409/get-version-of-exe-via-php by bilogic

  • 写回答

3条回答 默认 最新

  • doupai8533 2019-08-13 05:46
    关注

    \uXXXX is the JSON Unicode escape notation.

    if you are allowed to str_replace then use

    echo str_replace('\\u00000', "", $response);
    

    or use the JSON_UNESCAPED_UNICODE

    json_encode($array, JSON_UNESCAPED_UNICODE)
    
    评论

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败