json_encoded无法解码的字符串

时间:2014-12-29 16:43:10

标签: json

我已成功为下面的一个自定义对象生成了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>";
     }

1 个答案:

答案 0 :(得分:0)

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

UTF-8 character encoding battles json_encode()