的第一個條目我有這個JSON的URL:獲取JSON
{"success":true,"rgInventory":{"6073259621":{"id":"6073259621","classid":"1660549198","instanceid":"188530139","amount":"1","pos":1}}}
我需要獲得rgInventory
後的第一項。問題是,假設我不知道有"6073259621"
。我怎麼能不知道那裏有什麼?
我嘗試這一點,但不工作:
$obj = json_decode(file_get_contents($url), true);
$obj2 = json_decode(json_encode($obj['rgInventory']), true);
$obj3 = json_decode(json_encode($obj2), true);
echo $obj3;
使用'array_keys()'獲取密鑰以及獲取第一個密鑰然後獲得密鑰的用法。 – Rizier123
無需多次解碼。一旦你第一次解碼你將有一個數組,你可以遍歷。 –
你確實想返回6073259621或它所包含的數組嗎? – AbraCadaver