我嘗試將JSON對象放入一個PHP變量,它不工作。當我var_dump
它,它說NULL
。JSON解碼爲PHP不工作
PHP:
<?php
$json = utf8_encode(file_get_contents('http://socialclub.rockstargames.com/ajax/stat/1/profile_body/sta1/drantifat'));
$data = json_decode($json, false);
$money = $data->tplc->stats; // -> What do i have to do to reach the id:GTA Online Cash and use the val: $33.9K ?
?>
JSON文件如:(它隨時間變化)
{"cid":0,"ttl":"Grand Theft Auto V",
"ishs":false,"issa":false,"istc":false,"htl":true,"tlc":"text",
"tlt":"View Stats","tlh":"/member/drantifat/games/gtav/career/overview",
"iso":false,"cmng":false,"order":0,"uid":0,"ttc":0,
"tplc":"{\"game\":\"GTAV\",\"stats\":[{\"id\":\"Game Progress\",\"val\":\"58.77%\"},
{\"id\":\"Missions Passed\",\"val\":\"55\"},{\"id\":\"Playing Time\",\"val\":\"29:00:33\"},
{\"id\":\"GTA Online RP\",\"val\":\"2.4M\"},{\"id\":\"GTA Online Rank\",\"val\":\"128\"},
{\"id\":\"GTA Online Cash\",\"val\":\"$33.9K\"},
{\"id\":\"GTA Online Playing Time\",\"val\":\"529:44:12\"}],
\"url\":\"/member/drantifat/games/gtav/career/overview\"}","isa":false,"cnt":""}
誰能還幫我與我的PHP文件中已經提到過?
正如你可以在輸出時,看到'$數據 - > tplc'是另一個**字符串包含JSON **。 – 2014-09-12 22:46:44
希望我可以測試這個,該URL沒有返回任何數據 – wavemode 2014-09-12 22:50:28
@wavemode它的真實,我明白了。我很高興你說過,因爲我看到你必須登錄到Rockstar。我認爲我的'虛擬主機'沒有登錄到Rockstar讓我們這麼說。否則,它會工作?我會在localhost上測試它,並會再次迴應。 – 2014-09-12 22:57:50