解决方案 »
- 请教php大师---phpnewnew
- PHP多关键词搜索排序问题
- 下水道疏通的感觉,百度终于收录我的站了,呵呵,散分
- 麻烦帮我优化下这个SQL,谢谢
- 关于INT长度的问题,不解
- 灰常急用!!!php_imagick.dll扩展在windows下如何自己编译生成
- php与oracle连接设置
- 请教PHP的GET传值问题!
- $results = []
- tp5 怎么在后台执行 echo '<script> alert('XXX')</script> 这样的打印调试信息?
- 请问下https的网址php如何抓取。curl函数感觉已经被秒杀了!
- mysql_query()函数写在html中就会报错,写在外面就不行,求解决方法。
json_decode($json_str, true);
这样出来的就不是基类对象了
2、$ar[0]->comment->userName[0]->userName如果你是从 json 解码过来的数据,应给 json_decode 的第二个参数赋 true
$ar = json_decode($s, true)
或
$ar = json_decode($s, 1)
这样就全是数组了
1、$ar[0]['userName']
2、$ar[0]['comment']['userName'][0]['userName']
$obj->userName = 'cheng';
$arr = array($obj);echo $arr[0]->userName;
第二个$obj1 = new stdClass();
$obj1->userName = 'cheng';$obj = new stdClass();
$obj->did = 1;
$obj->comment = array('user_id'=>4,'userName'=>array($obj1));$arr = array($obj);
echo $arr[0]->comment['userName'][0]->userName;
如果简单点可以全部变数组$obj1 = new stdClass();
$obj1->userName = 'cheng';$obj = new stdClass();
$obj->did = 1;
$obj->comment = array('user_id'=>4,'userName'=>array($obj1));$arr = array($obj);$result = json_decode(json_encode($arr), true);print_r($result);
Array
(
[0] => Array
(
[did] => 1
[comment] => Array
(
[user_id] => 4
[userName] => Array
(
[0] => Array
(
[userName] => cheng
) ) ) ))