Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将JSON编码的文本转换为数组_Php_Json - Fatal编程技术网

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

Php 将JSON编码的文本转换为数组,php,json,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":"SAV

我有一个文本字符串,其编码方式如下:

 {"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_解码,但失败了。我认为这是由于特殊的字符和通用的格式。如何清理此文件以进行解码?

首先,您的字符串突然终止:
“17557036”:
是最后一个字符串-因此,JSON格式不正确。

您的文本无效或不完整。它在中途突然以“17557036”结尾:“可能您有文本限制,这会减少一些JSON。如果您是从DB获取的,那么应该使用大列来存储它。我可以使用正则表达式来删除剩余部分吗?删除了$posoflastcomma=strrpos($myText,,')之后的文本//最后一个逗号的位置$newText=substr_replace($myText,“,$posoflastcoma);在删除最后一个}json_decod之后的所有内容后,它工作得非常好。谢谢