I have a problem echo'ing data from a JSON file:
<?php
$url = file_get_contents("http://api.erpk.org/citizen/profile/3121752.json?key=Yn3AsG80");
$json = file_get_contents($url);
$data = json_decode($json, true);
echo "<pre>"; var_dump($data); echo"</pre>";
?>
the above is my php file i am using which outputs the JSON as shown below:
{
"id": 3121752,
"name": "SnowderBlazer",
"birth": "2010-04-10",
"avatar": "http://static.erepublik.net/uploads/avatars/Citizens/2010/04/10/4bb9a72cc291faaaf7af8e78ed0a8509_100x100.jpg",
"online": false,
"ban": null,
"alive": true,
"level": 97,
"experience": 360391,
"strength": 42859.62,
"rank": {
"points": 437120237,
"level": 64,
"image": "http://www.erepublik.com/images/modules/ranks/god_of_war_2.png",
"name": "God of War**"
},
"elite_citizen": false,
"national_rank": 1,
"residence": {
"country": {
"id": 65,
"name": "Serbia",
"code": "RS"
},
"region": {
"id": 198,
"name": "Midi-Pyrenees"
}
},
"citizenship": {
"id": 65,
"name": "Serbia",
"code": "RS"
},
"about": "Voters Club Moderator\ncatch me on #voters @Rizon\nIRC Nick : Snowderblazer OR Snowderblazer[BNC]\norder herehttp://erepublik-market.com/voters/newOrder.html?adp=1549866\n[ident:9vrwQZB9]",
"party": {
"id": 2479,
"name": "Ujedinjena eSrbija",
"role": "Party Member"
},
"army": {
"id": 1980,
"name": "Legija Stranaca Elite",
"role": "Commander",
"created_at": "2012-05-26",
"avatar": "http://static.erepublik.net/uploads/avatars/Groups/2012/05/26/f80bf05527157a8c2a7bb63b22f49aaa_medium.jpg",
"rank": "Commander"
},
"newspaper": {
"id": 241367,
"role": "Press director",
"name": "M.A.D.S News"
},
"top_damage": {
"damage": 215238312,
"date": "2013-05-16",
"message": "Achieved while successfully defending Basilicata against Italy on day 2,004"
},
"true_patriot": {
"damage": 3021790429,
"since": "2012-04-26"
},
"medals": {
"battle_hero": 248,
"campaign_hero": 98,
"congress_member": 9,
"country_president": 0,
"hard_worker": 36,
"media_mogul": 5,
"mercenary": 1,
"resistance_hero": 2,
"society_builder": 0,
"super_soldier": 171,
"top_fighter": 3,
"true_patriot": 43
},
"hit": 14924
}
my problem is just that it loads all data at once, and i only want to echo each i have no experience with JSON so i don't knwo the variables to echo
the via the JSON you can visit
JSON Version : http://api.erpk.org/citizen/profile/3121752.json?key=Yn3AsG80
XML Version : http://api.erpk.org/citizen/profile/3121752.xml?key=Yn3AsG80
What I want to achieve is the following:
- Load the JSON or XML without the output so that I can use the ECHO to put he data where i want it to show in the PHP file;
- ECHO each of the JSON or XML data.
Everytime I try I get an error that says its a non-object