php+json+decode+循环,php中json_decode及foreach使用总结

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 15:50   3297   0

《?php$arr=array();//例子1

$json_str= '{"ret":"OK","questions":{

"1":{"qid":"1","title":"\u95ee\u98981111",

"answers":{

"1":{"cid":"1","title":"A","cont":"\u7b54\u68481-1","iscorrect":"1","qid":"1"},

"2":{"cid":"2","title":"B","cont":"\u7b54\u68481-2","iscorrect":"0","qid":"1"},

"3":{"cid":"3","title":"C","cont":"\u7b54\u68481-3","iscorrect":"0","qid":"1"}

}},

"2":{"qid":"2","title":"\u95ee\u98982222",

"answers":{"5":{

"cid":"5","title":"A","cont":"\u7b54\u68482-1","iscorrect":"0","qid":"2"},

"6":{"cid":"6","title":"B","cont":"\u7b54\u68482-2","iscorrect":"0","qid":"2"},

"7":{"cid":"7","title":"A","cont":"aa","iscorrect":"0","qid":"2"},

"8":{"cid":"8","title":"D","cont":"\u7b54\u68482-4","iscorrect":"0","qid":"2"}}}}}';//相关错误反馈

// Notice: Undefined offset: 1

// Notice: Trying to get property of non-object

// Notice: Undefined offset: 0

// Notice: Array to string conversion

//json_decode不加参数true,转成的就不是array,而是对象 [questions] => stdClass Object

$arr=json_decode($json_str,true);//echo "

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP