如何使用PHP从json键值中删除所有双引号?

时间:2016-09-02 02:37:06

标签: php json

我收到了json数据。我想从json键中删除所有双引号,以便我能够解析我想要的数据。如果任何键上没有双引号,我的当前代码效果很好但是只要键中有双引号,我的代码就不会解析json数据!任何人都可以告诉我如何解决这个问题。谢谢

$code = stripslashes($_POST['outputtext']);
$data = json_decode($code, false);


foreach($data->videos as $item) {

   echo "<br>id: ".$item->id . "\n";
   echo "<br>title: ".$item->title . "\n";
   echo "<br>url: ".$item->url . "\n";
   echo "<br>img: ".$item->img . "\n";
   echo "<br>img: ".$item->description . "\n";
   echo "<br>";

}

JSON数据:

{
   "cat":{
      "id":"1234567",
      "source_id":null,
      "title_en":"first season",
      "description_en":"This is spring category "
   },
   "videos":[
      {
         "id":"312412343",
         "url":"\/2015-07-17\/1abcd.mp4",
         "img":"image\/44\/\/2015-07-17\/1abcd.jpg",
         "title":"first "title" here",
         "description":"some text" for description "here "
      },
      {
         "id":"2342343",
         "url":"\/2015-07-16\/2dcdeg.mp4",
         "img":"images\/44\/\/2015-07-16\/2dcdeg.jpg",
         "title":"second "title "here",
         "description":"some text" for description "here "
      }
   ]
}

0 个答案:

没有答案