【问题标题】:json_encoded String that cannot appear to be decoded似乎无法解码的 json 编码字符串
【发布时间】:2015-02-25 20:43:24
【问题描述】:

我已经成功地为一个自定义对象生成了下面的 json 表示。但是,当我使用 json_decode(jsonObjectBelow) 时,我没有成功地将其转换为数组。我终于找到了为什么会这样。如果我删除带有重音符号的字符,例如“Muñoz-Gómez”,那么 json_decode(jsonObjectBelow) 可以工作,并且我能够生成我的数组并提取属性。出于实际目的,我无法搜索所有属性并删除这些重音...有解决方案吗?

json_object received: [{"abstractText":"Fevers of unknown origin (FUOs) may be due to any of over 200 different disorders. We present a most unusual case of an FUO in a returning traveler from the Dominican Republic. Work-up for Q fever, Brucellosis, Bartonella, malaria and HIV were negative, but very highly elevated ESRs and ferritin levels suggested possible Legionnaire\u0027s disease. This is the third reported case of Legionnaire\u0027s disease presenting as an FUO.","authorString":"Muñoz-Gómez S, Cunha BA.","issue":"1","journalTitle":"Heart Lung","pageInfo":"72-74","pmid":"25444558","pubYear":"2015","title":"Fever of unknown origin (FUO) due to Legionnaire\u0027s disease.","volume":"44"}]

此代码适用于没有重音的属性中的文本,但不适用于带有重音的文本。 我的php代码:

     //Get JSON POST
       $json = $_POST["jsonObj"];

     //Decode JSON into an Array
      $data = json_decode($json);

     for($i = 0; $i<count($data); $i++){

     echo "[".$i."]" . " " .$data[$i]->authorString . "/  " . $data[$i]->journalTitle . "<br>";
     }

【问题讨论】:

标签: json


【解决方案1】:

如果可能,尝试对值进行编码并发送 json 对象。请尝试以下链接中的步骤:

UTF-8 character encoding battles json_encode()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-14
    • 2013-06-15
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 2021-06-11
    • 2018-11-05
    相关资源
    最近更新 更多