{
"_": {
"APP_ID": "server_tracked"
},
"success": true,
"requestTime": "2013-08-20T11:37:12-07:00",
"shard": "Latin_America_North:ZWZkOGI1NjhhNTVmYTJkNDg0ODNjYzA2ZDIzZmM1MjcxOWEyNTgxOA",
"data": {
"accountId": 200087239,
"summonerId": 104046,
"name": "wilmerp",
"icon": 18,
"internalName": "wilmerp",
"level": 30
}
$objeto = json_decode(file_get_contents("http://forobeta.com/json.file"));
echo $objeto->atributo;
<?php
$json = '{
"_": {
"APP_ID": "server_tracked"
},
"success": true,
"requestTime": "2013-08-20T11:37:12-07:00",
"shard": "Latin_America_North:ZWZkOGI1NjhhNTVmYTJkNDg0ODNjYzA2ZDIzZmM1MjcxOWEyNTgxOA",
"data": {
"accountId": 200087239,
"summonerId": 104046,
"name": "wilmerp",
"icon": 18,
"internalName": "wilmerp",
"level": 30
}
}';
$jd = json_decode($json);
echo '<p>Icon: ' . $jd->data->icon . '</p>';
echo '<p>Level: ' . $jd->data->level . '</p>';
?>
<?php
$objeto = json_decode(file_get_contents("http://stats.lolperu.pe/info.php));
echo $objeto->success;
?>
Comillas al final de la URL. Te recomiendo hagas un var_dump($objeto); para que sepas que atributos recibes.disculpa mi ignorancia pero lo puse asi:
PHP:<?php $objeto = json_decode(file_get_contents("http://stats.lolperu.pe/info.php)); echo $objeto->success; ?>
y me salio esto:
Parse error: syntax error, unexpected $end in /home/wfackiuc/public_html/stats/prueba.php on line 6
Hola kazaf,
Para empezar, tu json no es válido, le falta un "}" al final, puedes comprobar la validez de un formato en JSONLint - The JSON Validator.
Además de esto, te dejo el código para que puedas recuperar data-icon y data-level, como ves es muy sencillo:
PHP:<?php $json = '{ "_": { "APP_ID": "server_tracked" }, "success": true, "requestTime": "2013-08-20T11:37:12-07:00", "shard": "Latin_America_North:ZWZkOGI1NjhhNTVmYTJkNDg0ODNjYzA2ZDIzZmM1MjcxOWEyNTgxOA", "data": { "accountId": 200087239, "summonerId": 104046, "name": "wilmerp", "icon": 18, "internalName": "wilmerp", "level": 30 } }'; $jd = json_decode($json); echo '<p>Icon: ' . $jd->data->icon . '</p>'; echo '<p>Level: ' . $jd->data->level . '</p>'; ?>
<?php
$jd = json_decode(file_get_contents('http://stats.lolperu.pe/info.php'));
echo '<p>Icon: ' . $jd->data->icon . '</p>';
echo '<p>Level: ' . $jd->data->level . '</p>';
?>
<?php
require_once './lib/Unirest.php';
$username = 'onisuka24';
$url = 'localhost/' . $username . '';
$json = Unirest::get($url, array("X-Mashape-Authorization" => "key"));
$json = $json->raw_body;
print_r($json);
$jd = json_decode($json);
echo '<p>Icon: ' . $jd->data->icon . '</p>';
echo '<p>Level: ' . $jd->data->level . '</p>';
echo '<p>Name: ' . $jd->data->name . '</p>';
?>
<?php
$username = $_GET['user'];
require_once './lib/Unirest.php';
$url = 'localhost/' . $username . '';
$json = Unirest::get($url, array("X-Mashape-Authorization" => "key"));
$json = $json->raw_body;
print_r($json);
$jd = json_decode($json);
echo '<p>Icon: ' . $jd->data->icon . '</p>';
echo '<p>Level: ' . $jd->data->level . '</p>';
echo '<p>Name: ' . $jd->data->name . '</p>';
?>
Te refieres a esto?
si tu url es este http://localhost/buscar.php?user=nick
entonces tu php con respecto a tu usuario seria..
Espero te sirva, Saludos y muchas bendiciones de igual manera ..PHP:<?php $username = $_GET['user']; require_once './lib/Unirest.php'; $url = 'localhost/' . $username . ''; $json = Unirest::get($url, array("X-Mashape-Authorization" => "key")); $json = $json->raw_body; print_r($json); $jd = json_decode($json); echo '<p>Icon: ' . $jd->data->icon . '</p>'; echo '<p>Level: ' . $jd->data->level . '</p>'; echo '<p>Name: ' . $jd->data->name . '</p>'; ?>
<?php
require_once './lib/Unirest.php';
$username = $_GET['user'];
$url = 'https://localhost/player/lan/' . $username . '';
$url2 = 'https://localhost/player/lan/' . $username . '/influence_points';
$json = Unirest::get($url, array("X-Mashape-Authorization" => "key"));
$json = $json->raw_body;
print_r($json);
$jd = json_decode($json);
echo '<p>Icon: ' . $jd->data->icon . '</p>';
echo '<p>Level: ' . $jd->data->level . '</p>';
echo '<p>Name: ' . $jd->data->name . '</p>';
?>
{
"_": {
"APP_ID": "server_tracked"
},
"success": true,
"requestTime": "2013-08-23T00:59:09-07:00",
"shard": "Latin_America_North:NzgwMmE2MGMzYmI2ZWQ5YTRiMWUzNWI3NmVmOTBhMzE2OTUxMmI4ZA",
"player": {
"accountId": 200087239,
"summonerId": 104046,
"name": "wilmerp",
"icon": 18,
"internalName": "wilmerp",
"level": 30
},
[CODE] "data": 250568[/CODE]
}
<?php
require_once './lib/Unirest.php';
$username = $_GET['user'];
$lan = 'https://localhost/player/lan/' . $username . '';
$puntos = 'https://localhost/player/lan/' . $username . '/influence_points';
$url = $lan;
$url2 = $puntos;
$json = Unirest::get($url, array("X-Mashape-Authorization" => "key"));
$json2 = Unirest::get($url2, array("X-Mashape-Authorization" => "key"));
$json = $json->raw_body;
print_r($json);
$jd = json_decode($json);
echo '<p>Icon: ' . $jd->data->icon . '</p>';
echo '<p>Level: ' . $jd->data->level . '</p>';
echo '<p>Name: ' . $jd->data->name . '</p>';
$json2 = $json2->raw_body;
print_r($json2);
$jd2 = json_decode($json2);
echo '<p>Puntos: ' . $jd2->data . '</p>';
?>
Utilizamos cookies y tecnologías similares para los siguientes fines:
¿Aceptas las cookies y estas tecnologías?
Utilizamos cookies y tecnologías similares para los siguientes fines:
¿Aceptas las cookies y estas tecnologías?