任何人都可以在這裏幫助我一個解碼json?我試着去解碼JSON API URLPHP解碼json
這裏是我的時刻:
$string = '
{
"username": "someusername",
"unconfirmed_reward": "0.08681793",
"send_threshold": "0.01000000",
"confirmed_reward": "0.02511418",
"workers":
{
"bitcoinjol.jason-laptop": {"last_share": 1307389634, "score": "0", "hashrate": 0, "shares": 0, "alive": false},
"bitcoinjol.david-laptop": {"last_share": 1307443495, "score": "1.7742", "hashrate": 24, "shares": 1, "alive": true},
"bitcoinjol.pierre-pc": {"last_share": 1307441804, "score": "0", "hashrate": 0, "shares": 0, "alive": true},
"bitcoinjol.testJol": {"last_share": 0, "score": "0", "hashrate": 0, "shares": 0, "alive": false}
},
"wallet": "asdasdjsadajdasjdsajasjdajdajs",
"estimated_reward": "0.00131061"
}';
$json_o = json_decode($string);
echo $json_o->username;
這種打印出「someusername」,但我不能把它打印出來的工人,當我嘗試:
echo $json_o->workers->someusername.jason-laptop;
我認爲「。」或者我使用的「 - 」是無效的?
我希望能夠打印出每個工人,然後打印出waller,用戶名和獎勵等。 使用數組或這些對象,無論哪種方式。我也嘗試用爆炸分割$,「」,但無法讓它很好地工作。
運行Server 2008 R2與PHP 5.3和IIS 7.5
使用print_r();在數組或對象上顯示詳細信息。回聲僅適用於字符串。 – hakre 2011-06-07 11:51:38