我尝试读取 JSON 对象并对其进行解析。我正在使用的代码如下:
<?php
$json_string2 = '{"Products":[
{"Size":"klklkkl",
"No":"1352285923",
"KnowDate":true,
"Subdata":[
{
"item" : "1",
},
{
"item" : "455",
}],
"Info":true
}]
}';
$obj = json_decode($json_string2, true);
foreach($obj as $key => $value)
{
$size = $value->{'Size'};
$no = $value->{'No'};
$knowdate = $value->{'KnowDate'};
$info = $value->{'Info'};
}
.
.
?>
但是在进入 for 循环的行中,我收到以下错误:
Notice: Trying to get property of non-object in C:\xampp\htdocs\PhpProject2\parseJson.php on line...
这个问题的解决方案是什么?有人知道吗?