-4

I'd love to start programming in JSON, for riot api, but I don't know how to start it.. I have done something like that, but this doesn't show anything lol.. Just white page.

    <html>
<head>
<title>JSON example</title>
<script language="javascript" >
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://euw.api.pvp.net/api/lol/euw/v2.5/league/by-summoner/31827832?api_key=myapikey');

// Set so curl_exec returns the result instead of outputting it.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Get the response and close the channel.
$response = curl_exec($ch);
curl_close($ch);

$json = json_decode($response, true);

foreach($json as $elem){
    echo $elem[0]['name'];
    echo $elem[0]['tier'];
}
</script>
</head>
<body>
</body>
</html>
Piotr Sawicki
  • 11
  • 1
  • 2

1 Answers1

0

Please take a look at these guides I wrote for an introduction to the Riot API and using/understanding JSON.

While you can use many languages like PHP, I teach it in Javascript/Ajax/JQuery as that knowledge than be applied to other languages pretty easily, especially with PHP since the syntax of both look decently similar.

[Tutorial] Beginners introduction to Riot API and JSON, using Javascript and Ajax

I discuss what the API is and how you use it, as well as securing your key. I also mention JSON and how to access and understand it with a program.

Let me know if you have any questions.

Austin
  • 3,010
  • 23
  • 62
  • 97