当前位置:Gxlcms > PHP教程 > 请用json_decode解析成数组解决方法

请用json_decode解析成数组解决方法

时间:2021-07-01 10:21:17 帮助过:57人阅读

请用json_decode解析成数组
jsonp107({"SM_368_dsr-1097280647":{v:0,nv:100,m_UFB:0,m:4.89661,m_g:20.15,s_UFB:0,s:4.8744,s_g:31.49,c_UFB:0,c:4.87867,c_g:39.55,gp:100.00,ss:290167,hdr:true},"ICCP_1_522177046867":4915});


我要取4915这个值,请用json_decode解析成数组来取值。

求这几行代码
------解决思路----------------------
$s =<<< TXT
jsonp107({"SM_368_dsr-1097280647":{v:0,nv:100,m_UFB:0,m:4.89661,m_g:20.15,s_UFB:0,s:4.8744,s_g:31.49,c_UFB:0,c:4.87867,c_g:39.55,gp:100.00,ss:290167,hdr:true},"ICCP_1_522177046867":4915});
TXT;
$s = preg_replace_callback('/[-".\w]+/',
function($m) { return '"' . trim($m[0],'"') . '"'; },
preg_replace('/^.+\((.+)\).+$/', '$1', $s));
print_r(json_decode($s, 1));
Array
(
[SM_368_dsr-1097280647] => Array
(
[v] => 0
[nv] => 100
[m_UFB] => 0
[m] => 4.89661
[m_g] => 20.15
[s_UFB] => 0
[s] => 4.8744
[s_g] => 31.49
[c_UFB] => 0
[c] => 4.87867
[c_g] => 39.55
[gp] => 100.00
[ss] => 290167
[hdr] => true
)

[ICCP_1_522177046867] => 4915
)

人气教程排行