解码json时遇到问题。 这是Google Chrome和Java认可的json屏幕。
Chrome:https://ibb.co/gZ33Qa
Android Studio:https://ibb.co/kTXV5a
我无法通过json_decode()在PHP中解码它,错误号4是语法错误。 你怎么能修好这个json?
杰森自己
{"rs":[["addChd",["sFCF6",[
['zul.wgt.Div','sFCFb',{sclass:'transparent table contentHolder',prolog:'\n '},[
['zk.Native','sFCFc',{prolog:'\n
<h1>Управляющая компания',epilog:'</h1>'},[]],
['zk.Native','sFCFd',{prolog:'\n
<table>\n ',epilog:'\n </table>'},[
['zk.Native','sFCFe',{prolog:'
<tr>\n
<td colspan="2">\n ',epilog:'\n </td>\n
</tr>'},[
['zul.wgt.Label','sFCFf',{id:'nameLabel',sclass:'value',style:'font-weight: bold',value:'Общество с ограниченной ответственностью Управляющая компания "Якутск"'},[]]]],
['zk.Native','sFCFg',{prolog:'\n '},[]],
['zk.Native','sFCFh',{prolog:'
<tr>\n
<td colspan="2">\n ',epilog:'\n </td>\n
</tr>'},[
['zul.wgt.Label','sFCFi',{id:'addressLabel',sclass:'value',multiline:true,value:'РС (Я), г.Якутск, ул.Орджоникидзе, д.38'},[]]]],
['zk.Native','sFCFj',{prolog:'\n '},[]],
['zk.Native','sFCFk',{prolog:'
<tr>\n
<td>Телефоны:</td>\n
<td>\n ',epilog:'\n </td>\n
</tr>'},[
['zul.wgt.Label','sFCFl',{id:'phoneLabel',sclass:'value',value:'8(4112) 40-56-41'},[]]]],
['zk.Native','sFCFm',{prolog:'\n '},[]],
['zk.Native','sFCFn',{prolog:'
<tr>\n
<td>Директор:</td>\n
<td>\n ',epilog:'\n </td>\n
</tr>'},[
['zul.wgt.Label','sFCFo',{id:'directorLabel',sclass:'value',value:'Молонов Алексей Владимирович тел.: 89142946345'},[]]]],
['zk.Native','sFCFp',{prolog:'\n '},[]],
['zk.Native','sFCFq',{prolog:'
<tr>\n
<td>Бухгалтер:</td>\n
<td>\n ',epilog:'\n </td>\n
</tr>'},[
['zul.wgt.Label','sFCFr',{id:'accounterLabel',sclass:'value',value:'Антипина Русалина Николаевна тел.: 89142946345'},[]]]],
['zk.Native','sFCFs',{prolog:'\n '},[]],
['zk.Native','sFCFt',{prolog:'
<tr>\n
<td>Эл. адрес:</td>\n
<td>\n ',epilog:'\n </td>\n
</tr>'},[
['zul.wgt.Label','sFCFu',{id:'emailLabel',sclass:'value',value:'kk_centr_2013@mail.ru'},[]]]]]],
['zk.Native','sFCFv',{prolog:'\n
<br/>'},[]],
['zul.box.Vlayout','sFCFw',{id:'noteHolder',prolog:'\n '},[]],
['zk.Native','sFCFx',{prolog:'\n
<br/>'},[]]]]]]],["script",["jq('.contentHolder').hide().fadeIn(500); select_menu_item('organization');"]]],"rid":1}
答案 0 :(得分:0)
我认为问题在于API提供的内容。我过去遇到过类似的问题,Google API提供的JSON不正确。
您可以尝试以下方法:
用双引号替换单引号:
$result=str_replace($test,'\'','"');
使用preg_replace
用双引号括起键:
$pattern='/\b([^"].*?[^"])\b:(.*?[,}])/';
$result=preg_replace($pattern,'"\1":\2',$result);
这可能会有所帮助。
答案 1 :(得分:0)
阅读您发送的代码,只是为了使其有效,您可以:
try {
$decrypted = json_decode($result);
} catch(Exception $e) {
$sane = str_replace('="', '=\"', $result);
$healthy = str_replace('">', '\">', $sane);
$decrypted = json_decode($healthy);
}
这是一个黑客。我会推荐我们的案例,即:
"
解决方案可能是使用json字符串中的prolog键解析每个对象: