Heim  >  Artikel  >  Backend-Entwicklung  >  请问个json解析有关问题

请问个json解析有关问题

WBOY
WBOYOriginal
2016-06-13 10:11:01830Durchsuche

请教个json解析问题
我有几个json串

HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->{"clusterno":167145108,"clustertype":1,"subid":"0","newperson":"欢迎【.dazuo.昵称.dayou.】来到群【.dazuo.群名.dayou.】.enter.信息:.enter..dazuo.信息.dayou..enter..dazuo.退群次数.dayou..enter.请改群名片:帮派名┃职位 或者 帮派名┃职位┃昵称.enter.名称不符.douhao.不改名者送去夏威夷...enter..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..enter.\.douhao.\是机器人.douhao.请直接无视忽略.","removeperson":"","expdatetime":"2021-10-18 23:50:42","userid":"1","username":"admin","updatecode":"7ECEDB4E1037476EAAF5FB5E8340AAEE"}


用json_decode解析会出现是null的.

我测试了 一下,是newperson这个接点太长导致的,有没有什么方法可以解决这个问题

------解决方案--------------------
反斜杠转义,转换编码
PHP code
<?php $json='{"clusterno":167145108,"clustertype":1,"subid":"0","newperson":"欢迎【.dazuo.昵称.dayou.】来到群【.dazuo.群名.dayou.】.enter.信息:.enter..dazuo.信息.dayou..enter..dazuo.退群次数.dayou..enter.请改群名片:帮派名┃职位 或者 帮派名┃职位┃昵称.enter.名称不符.douhao.不改名者送去夏威夷...enter..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..jhao..enter.\.douhao.\是机器人.douhao.请直接无视忽略.","removeperson":"","expdatetime":"2021-10-18 23:50:42","userid":"1","username":"admin","updatecode":"7ECEDB4E1037476EAAF5FB5E8340AAEE"}';$json=addcslashes($json,'\\');var_dump(json_decode(iconv('GBK','UTF-8',$json),true));?><br><font color="#e78608">------解决方案--------------------</font><br>utf-8编码文件就不需要再  iconv了.参考楼上的.<br><font color="#e78608">------解决方案--------------------</font><br>
探讨

反斜杠转义,转换编码
PHP code
$json='{"clusterno":167145108,"clustertype":1,"subid":"0","newperson":"欢迎【.dazuo.昵称.dayou.】来到群【.dazuo.群名.dayou.】.enter.信息:.enter..dazuo.信息.dayou..enter..dazuo.退群次数.dayou..……
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn