Autor Zpráva
objGET
Profil *
Dobry den,
mam tento json:
{
    "appnews": {
        "appid": 440,
        "newsitems": [
            {
                "gid": "521612247017608543",
                "title": "Team Fortress 2 Update Released",
                "url": "http://store.steampowered.com/news/externalpost/tf2_blog/521612247017608543",
                "is_external_url": true,
                "author": "",
                "contents": "An update to Team Fortress 2 has been released. The update will be applied automatically when you restart Team Fortress 2. The major changes include: * Fixed a problem that was preventing clients from uploading items to the Steam Workshop ",
                "feedlabel": "TF2 Blog",
                "date": 1410386700,
                "feedname": "tf2_blog"
            },
            {
                "gid": "521612247017428766",
                "title": "Team Fortress 2 Update Released",
                "url": "http://store.steampowered.com/news/14354/",
                "is_external_url": false,
                "author": "Valve",
                "contents": "An update to Team Fortress 2 has been released. The update will be applied automatically when you restart Team Fortress 2. The major changes include: * Fixed a problem that was preventing clients from uploading items to the Steam Workshop; ",
                "feedlabel": "Product Update",
                "date": 1410386700,
                "feedname": "steam_updates"
            },
            {
                "gid": "521612247015463937",
                "title": "Team Fortress 2 Update Released",
                "url": "http://store.steampowered.com/news/externalpost/tf2_blog/521612247015463937",
                "is_external_url": true,
                "author": "",
                "contents": "An update to Team Fortress 2 has been released. The update will be applied automatically when you restart Team Fortress 2. The major changes include: * Added taunts to the items that can be uploaded to the Steam Workshop ;* Added new \"Taunt\" and \"Halloween\" tags to the Steam Workshop; * Previous ent...",
                "feedlabel": "TF2 Blog",
                "date": 1410382620,
                "feedname": "tf2_blog"
            }
        ]
        
    }
}

A v PHP
$obj = json_decode($json);
print $obj->{'gid'}; 
- v json je ten json, ktery mam ulozeny na jinem serveru a nacitam ho pres file_get_contents, ovsem nevim, jak nacist jednotlivy udaj/hodnotu.
Napriklad chci vytahnout "hodnotu" u "gid" a napise mi to toto:

Notice: Undefined property: stdClass::$gid in *\json.php on line 
Mohl by mi to nekdo vysvetlit? Delam s tou funkci poprve. DIky.
Fisir
Profil
Reaguji na objGETa:
json_decode() vrací pole.
abc
Profil
Najdeš to v
$obj->appnews->newsitems[0]->gid;



Fisir:
Reaguji na objGETa:
json_decode() vrací pole.
Pouze pokud je druhý parametr TRUE jinak vrací objekt
objGET
Profil *
Diky moc.

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0