擷取某一元素有關問題,
來源:互聯網
上載者:User
擷取某一元素問題,急
{"head":[{"visitcode":"sjbtg","resultCode":"0"}],"content":[{"userID":"15611030868","productID":"3111007900 ","orderTime":"2012-06-19","orderType":"1","orderresult":"6","orderremark":"輸入的產品ID不存在","baseLine":"","orderField":""},{"userID":"","productID":"","orderTime":"","orderType":"1","orderresult":"1","orderremark":"輸入必選參數為空白","baseLine":"","orderField":""},{"userID":"","productID":"","orderTime":"","orderType":"1","orderresult":"1","orderremark":"輸入必選參數為空白","baseLine":""}]}
怎麼得到其中"orderresult":"6"的值,也就是6
------解決方案--------------------
$s = '{"head":[{"visitcode":"sjbtg","resultCode":"0"}],"content":[{"userID":"15611030868","productID":"3111007900 ","orderTime":"2012-06-19","orderType":"1","orderresult":"6","orderremark":"輸入的產品ID不存在","baseLine":"","orderField":""},{"userID":"","productID":"","orderTime":"","orderType":"1","orderresult":"1","orderremark":"輸入必選參數為空白","baseLine":"","orderField":""},{"userID":"","productID":"","orderTime":"","orderType":"1","orderresult":"1","orderremark":"輸入必選參數為空白","baseLine":""}]} ';
echo json_decode($s)->content[0]->orderresult; //6
------解決方案--------------------
探討
$s = '{"head":[{"visitcode":"sjbtg","resultCode":"0"}],"content":[{"userID":"15611030868","productID":"3111007900 ","orderTime":"2012-06-19","orderType":"1","orderresult":"6","orderremark":"輸入的產品ID不存……