奇怪的JSON对象,如何用PHP解码它

时间:2016-02-15 13:56:25

标签: php json

我完全被误解了,如何使用PHP获取此JSON对象的值?

例如,获取“”的正确行是什么?

这是我到目前为止所做的:

$jsonURL = 'this Url retursn the json below';
$urlObject = file_get_contents($jsonURL);
$jsonObject = json_decode($urlObject, true);
echo $jsonObject[2]['SERVER_INFO'];

这是我的JSON对象:

array(3)
{ ["type"]=> string(7) "success"
  ["message"]=> array(4){
    ["SERVER_INFO"]=> array(35){
      ["map"]=> string(9) "MP_Prison"
      ["gameId"]=> string(17) "18014398521571987"
      ["gameExpansions"]=> array(1) { [0]=> int(0) }
      ["mapMode"]=> string(1) "1"
      ["ip"]=> string(13) "5.101.165.124"
      ["matchId"]=> string(1) "0"
      ["protocolVersionString"]=> string(4) "4900"
      ["extendedInfo"]=> array(3)
        {
          ["message"]=> string(51) ""
          ["bannerUrl"]=> string(0) ""
          ["desc"]=> string(27) "Go"
        }
        ["game"]=> int(2048)
        ["ranked"]=> int(1)
        ["online"]=> int(1)
        ["platform"]=> int(1)
        ["tickRateMax"]=> int(30)
        ["updatedAt"]=> int(1455543633)
        ["slots"]=> array(4) {
          [8]=> array(2) {
            ["current"]=> int(0)
            ["max"]=> int(0)
          } [1]=> array(2) { ["current"]=> int(0) ["max"]=> int(20) } [2]=> array(2) { ["current"]=> int(0) ["max"]=> int(22) } [4]=> array(2) { ["current"]=> int(0) ["max"]=> int(2) } } ["guid"]=> string(36) "21268f3e-1d68-4ee7-9802-35b4d88d187a" ["port"]=> int(38200) ["punkbuster"]=> int(1) ["playlist"]=> int(0) ["gameExpansion"]=> string(1) "0" ["name"]=> string(60) "" ["settings"]=> array(39) { ["vgmc"]=> int(400) ["gmwp"]=> int(0) ["vinb"]=> int(0) ["vfrm"]=> int(0) ["v3ca"]=> int(1) ["vnta"]=> int(1) ["vtbr"]=> int(100) ["vaba"]=> int(1) ["vmst"]=> int(0) ["vprc"]=> int(1) ["vmsp"]=> int(1) ["vrlc"]=> int(10) ["v3sp"]=> int(1) ["osls"]=> int(0) ["aaro"]=> int(0) ["vprp"]=> int(33) ["vprt"]=> int(100) ["vbdm"]=> int(100) ["vicc"]=> int(0) ["vvsa"]=> int(1) ["vvsd"]=> int(100) ["vkca"]=> int(1) ["vnip"]=> int(22) ["vtkk"]=> int(3) ["vhit"]=> int(1) ["vnit"]=> int(300) ["vrtl"]=> int(100) ["vtkc"]=> int(5) ["vhud"]=> int(1) ["vmin"]=> int(1) ["vrhe"]=> int(1) ["vcmd"]=> int(1) ["vrsp"]=> int(4) ["vshe"]=> int(100) ["vffi"]=> int(0) ["aasl"]=> int(0) ["vmpl"]=> int(24) ["vprb"]=> int(180) ["vsbb"]=> int(1) } ["fairfight"]=> int(1) ["region"]=> int(16) ["mapVariant"]=> int(0) ["ping"]=> int(999) ["serverType"]=> int(2) ["experience"]=> string(1) "0" ["tickRate"]=> int(60) ["hasPassword"]=> int(0) ["maps"]=> array(5) { ["maps"]=> array(1) { [0]=> array(3) { ["mapMode"]=> string(1) "1" ["map"]=> string(9) "MP_Prison" ["mapVariant"]=> int(0) } } ["currentMapRound"]=> int(0) ["nextMapIndex"]=> int(0) ["currentMapIndex"]=> int(0) ["numberMapRounds"]=> int(1) } ["secret"]=> string(0) "" ["preset"]=> int(1) ["pingSite"]=> string(3) "ams" ["country"]=> string(2) "de" } ["friendsWithFavServer"]=> NULL ["SERVER_PLAYERS"]=> array(0) { } ["isFavorite"]=> bool(false) } ["data"]=> array(0) { } }

1 个答案:

答案 0 :(得分:2)

$jsonObject["message"]["SERVER_INFO"]["slots"]["name"];