Php json decode return null

来源:互联网 发布:淘宝上的玛卡是真的吗 编辑:程序博客网 时间:2024/05/21 18:44

php json_decode will return a null answer when it
get ‘\uxxxx’ character since it only supports UTF-8 which was
declared by official website.

So how could we solve this question when we
want to json_decode(Chinese)?

Here provide two way to solve this:

  1. $pp = '{"\u8499\u9a6c\u7279\u9057\u4e66\uff08\u8bd5\u8bfb\uff09": "https://read.douban.com/ebook/256340/", "\u6587\u5b66\u56de\u5fc6\u5f55\uff08\u8bd5\u8bfb\uff09": "https://read.douban.com/ebook/451767/", "\u6587\u5b66\u56de\u5fc6\u5f55\uff1a\u4e2d\u4e16\u7eaa\u2014\u5341\u4e03\u4e16\u7eaa\u4e4b\u5377": "https://read.douban.com/ebook/9837704/", "\u6587\u5b66\u56de\u5fc6\u5f55\uff1a\u53e4\u4ee3\u4e4b\u5377": "https://read.douban.com/ebook/9837472/", "\u6587\u5b66\u56de\u5fc6\u5f55\uff1a\u5341\u516b\u2014\u5341\u4e5d\u4e16\u7eaa\u4e4b\u5377": "https://read.douban.com/ebook/9841737/"}';        echo var_dump(json_decode($pp)); 

    As you can see, we change the \" to "

  2. And this is the second way, I love it.

$pp = '{\"\u8499\u9a6c\u7279\u9057\u4e66\uff08\u8bd5\u8bfb\uff09\": \"https://read.douban.com/ebook/256340/\", \"\u6587\u5b66\u56de\u5fc6\u5f55\uff08\u8bd5\u8bfb\uff09\": \"https://read.douban.com/ebook/451767/\", \"\u6587\u5b66\u56de\u5fc6\u5f55\uff1a\u4e2d\u4e16\u7eaa\u2014\u5341\u4e03\u4e16\u7eaa\u4e4b\u5377\": \"https://read.douban.com/ebook/9837704/\", \"\u6587\u5b66\u56de\u5fc6\u5f55\uff1a\u53e4\u4ee3\u4e4b\u5377\": \"https://read.douban.com/ebook/9837472/\", \"\u6587\u5b66\u56de\u5fc6\u5f55\uff1a\u5341\u516b\u2014\u5341\u4e5d\u4e16\u7eaa\u4e4b\u5377\": \"https://read.douban.com/ebook/9841737/\"}';$python = '"'.$pp.'"';echo json_decode($python);
原创粉丝点击