将JSON编码的文本转换为数组

时间:2012-09-15 02:13:05

标签: php json

我有一串以这种方式编码的文字:

 {"itemId":"17417362","type":"0","cclass":0,"value":"100","category":null,"image":{"url":"\/\/cdn.site.com\/insight.site.com\/COS20\/_Cache\/_ImageCache\/362\/17417362.gif","height":"100","width":"80"},"burstText":"","summary":"SAVE $1.00 ON TWO","brand":"Big \u00ae","link_text":"","link_url":"","activated":"2012-09-01T00:01:00","expiration":"2012-10-31T23:59:00","isuff":"362\/17417362.gif","imagePrefix":null,"details":"when you buy TWO BOXES: Original \u00ae ...","catid":"531","catdesc":"Ready to Eat","slot":"-415","prodinfo":"when you buy TWO BOXES any flavor: Original \u00ae \u2022 \u00ae \u202 \u00ae...","cpnuse":"1","printed":null,"actiontaken":null,"printCount":null,"onCard":null,"sid":"11079187","fid":"06338174","videoURL":"","catlevel1":"107","catlevel2":"399","catlevel3":"531","catdesc1":"Foods","catdesc2":"Breakfast","catdesc3":"Ready to Eat","restricted":0},"17557036":

我在这个字符串上尝试过json_decode但它失败了。我认为这是由于特殊字符和一般格式。如何清理它以进行解码?

1 个答案:

答案 0 :(得分:3)

对于初学者来说,你的字符串突然终止:"17557036":是最后一个 - 因此,没有格式良好的JSON。