我有一個JSON飼料是私人(通過IP地址),我可以使用命令解析JSON提要到PHP,然後處理數據?
$json = file_get_contents("http://#");
這是進是什麼樣子,並命令作品解析 - 它正確轉儲數據使用json_decode時($ JSON);或者json_decode($ json,true);我做了一個var轉儲。
{
"Holder": [
{
"name": "Subholder One",
"operators": [
{
"username": "User1",
"status": 3
},
{
"username": "User2",
"status": 3
},
{
"username": "User3",
"status": 3
},
{
"username": "User4",
"status": 1
}
]
},
{
"name": "Subholder Two",
"operators": [
{
"username": "User5",
"status": 3
}
]
},
{
"name": "Subholder Three",
"operators": [
{
"username": "User6",
"status": 3
}
]
},
{
"name": "Subholder Four",
"operators": [
{
"username": "User7",
"status": 1
},
{
"username": "User8",
"status": 3
},
{
"username": "User9",
"status": 1
}
]
}
]
}
當我使用簡單,下面有一行數據的代碼,用沒有的file_get_contents但數據線工作原理:
$obj = json_decode($json);
echo $obj->username;
echo $obj->status;
當我使用的file_get_contents它不工作。
我希望能夠做的就是顯示所有數據的用戶名和狀態(將數字轉換成我已經完成的一個詞組),並且通過用戶名單獨顯示。
例如在用戶1的個人資料頁面上,我想解析他們的「用戶名」和「狀態」,將狀態號碼轉換爲相應的短語並顯示在屏幕上。
我在這裏撓我的頭...所以任何幫助感激地收到。
你還沒有得到有效的JSON數據。 –
將file_get_contents結果粘貼到此處。也許這個功能不允許通過http獲取內容? (php.ini) – mblaettermann
你可以將json_decode之前的結果粘貼到file_get_contents中嗎?因爲你在上面的問題粘貼的JSON代碼是有效的 – GBD