dongzha3058 2013-11-30 07:49
浏览 92
已采纳

在json解码中格式化

I've question about decodings There is translatsions.php like

<?php
    define("LNG_T1","sdfjaö");
    define("LNG_T2","õäöüåÕÄÖÜ");
    define("LNG_T3","Русский");
    define("LNG_T4","Українська");
    define("LNG_T5","日本語");
    define("LNG_T6","العربية");
?>

And there is another php-file

<?php

    function startsWith($haystack, $needle) {
        return !strncmp($haystack, $needle, strlen($needle));
    }
    require_once 'translatsions.php';
    header('Content-type: text/javascript; charset=UTF-8');

    $res = array();
    foreach (get_defined_constants() as $k => $v) {
        if (startsWith($k, "LNG_")) {
            $v = preg_replace('/\'/', '&#39;', $v);
            $k = strtolower(substr($k, 4));
            $res[$k] = $v;
        }
    }

?>

echo json_encode($res, JSON_PRETTY_PRINT) And i want to see json

{
    "t1":"sdfjaö",
    "t2":"õäöüåÕÄÖÜ",
    "t3":"Русский",
    "t4":"Українська",
    "t5":"日本語",
    "t6":"العربية"
}

not json like:

{
    "t1": "sdfja\u00f6",
    "t2": "\u00f5\u00e4\u00f6\u00fc\u00e5\u00d5\u00c4\u00d6\u00dc",
    "t3": "\u0420\u0443\u0441\u0441\u043a\u0438\u0439",
    "t4": "\u0423\u043a\u0440\u0430\u0457\u043d\u0441\u044c\u043a\u0430",
    "t5": "\u65e5\u672c\u8a9e",
    "t6": "\u0627\u0644\u0639\u0631\u0628\u064a\u0629"
}

Has PHP any such universal function?

  • 写回答

1条回答 默认 最新

  • dongru3726 2013-11-30 07:52
    关注

    Use the JSON_UNESCAPED_UNICODE option as well as JSON_PRETTY_PRINT

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 无源定位系统的时差估计误差标准差
  • ¥15 请问这个代码哪里有问题啊
  • ¥20 python--version在命令端输入结果Python is not defined怎么办?还有pip不是exe格式是不是没安装成功?
  • ¥15 通过GaussianView进行结构微调消除虚频
  • ¥15 调用transformers库
  • ¥15 由于导出的数据名字中带有/,导致Matlab打不开,怎么办?
  • ¥15 新硬盘安装的程序总是崩溃,提示遇到错误
  • ¥15 openpcdet自制数据集评估bev精度和3d精度相同
  • ¥15 excel 上下按钮 显示行
  • ¥20 云卓h12pro 数传问题