我试图爆炸一些JSON,但是我收到错误,"Undefined offset: 1."
我不知道如何解决它。我试着var_dump
JSON内容,它显示了我需要的字符串单词。但是,当我尝试explode
和foreach
时,我收到错误消息。请帮我。
这是代码:
$json = file_get_contents('http://localhost/project/services/grafik');
$encoding = json_encode($json,true);
$pecah = explode(",",$encoding);
// var_dump($pecah);
foreach($pecah as $row => $data)
{
$p1 = explode(',', $data);
$p2[$row] = explode(',',$p1[0]);
$nama=$p2[$row][0];
$jumlah=$p2[$row][1];
}
这是JSON内容:
"Windows XP Prof ,106, Windows 7 ,43, Windows Vista Business ,13, Windows 7 Prof ,21, B4 ,1, Windws 7 Prof ,1, IPCOP ,1, Windows 2003 server ,4, Windows 2008 server ,1, Windows 2008 R2 ,4, NULL ,9, Windows 8 Prof ,6,operating,1,"