2

I'm trying to get data from an API in symfony. here's my code:

$champion_details_json = file_get_contents('https://global.api.pvp.net/api/lol/static-data/euw/v1.2/champion?api_key=mykey');

$obj2 = json_decode($champion_details_json);
$championDetailData = $obj2->data;


return $this->render('default/action.html.twig', compact('championData', 'championDetailData'));

Here's what a var dump shows me on the screen:

object(stdClass)[386]
public 'Thresh' => 
object(stdClass)[385]
  public 'id' => int 412
  public 'key' => string 'Thresh' (length=6)
  public 'name' => string 'Thresh' (length=6)
  public 'title' => string 'the Chain Warden' (length=16)
public 'Aatrox' => 
object(stdClass)[387]
  public 'id' => int 266
  public 'key' => string 'Aatrox' (length=6)
  public 'name' => string 'Aatrox' (length=6)
  public 'title' => string 'the Darkin Blade' (length=16)

Here's what the api's tells me i get back:

{
"data": {
  "Aatrox": {
     "id": 266,
     "title": "the Darkin Blade",
     "name": "Aatrox",
     "key": "Aatrox"
  },
  "Thresh": {
     "id": 412,
     "title": "the Chain Warden",
     "name": "Thresh",
     "key": "Thresh"
  },
0

1 Answer 1

2

use json_decode($champion_details_json, true); true flag returns array instead of object

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.