PHP解析json 并获取元素的值

";
print_r($J);
print_r("
"); echo "测试访问对象内元素
"; print_r($J->item1->item11->n."
"); print_r($J->item1->sex."
"); //注意不是标准的json print_r($J->item2->age."
"); ?>


屏幕打印如下


通过下面的信息就可以获取里面的信息了
stdClass Object ( [item1] => stdClass Object ( [item11] => stdClass Object ( [n] => chenling [m] => llll ) [sex] => 男 [age] => 25 ) [item2] => stdClass Object ( [item21] => ling [sex] => 女 [age] => 24 ) )
测试访问对象内元素
chenling

24

你可能感兴趣的:(PHP解析json 并获取元素的值)