0
我從REST的API獲取JSON數據JSON值如下:檢索PHP
//manipute json
{
"email": "[email protected]",
"phone": "123456789",
"address": {
"line1": "2/15 street",
"line2": "Lonsdale",
},
"extrafields": [
{
"key": "firstname",
"value": "Robert"
},
{
"key": "lastname",
"value": "Allen"
},
],
}
$obj=json_decode($output); //$output the retrieved JSON which is decoded in php
// Code below works fine to get the "email" value
$s = $obj->{'email'};
// Code below works fine to get the line1 of "address"
$s = $obj->address->{'line1'};
請幫助我的代碼來檢索的關鍵=「名字」值
這將讀取第一個額外字段的密鑰,而不是使用密鑰'firstname'的值。他們巧合的是一樣的,但假設這樣的事情是不可靠的。 – GolezTrol 2014-09-20 17:20:15