Q: /game info isn't loading properly

Avatar image for martijnotter
martijnotter

6

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#1  Edited By martijnotter

Hey all, I hope someone can help me with this.

I use this code with all of my pages, and it always works, except for /game. I can choose certain parts of all the data. For example in my image I request the 'name'. But when I try to do this with /game, I don't get a result. I only get results when using 'data' instead of 'data.name'. But this displays all the data, and using field_list filters isn't a good option to use. Anyone who knows why this isn't working? Thanks in advance!

No Caption Provided

Avatar image for laika
laika

148

Forum Posts

1

Wiki Points

0

Followers

Reviews: 0

User Lists: 1

#2  Edited By laika

Since you're querying on the /game (singular) endpoint, the "results" key contains an object (the game), rather than an array. If you're looking for the publisher names, try `$.each(data.results.publishers)`.

Avatar image for martijnotter
martijnotter

6

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#3  Edited By martijnotter

@laika: Great, that's working! Now there is one last issue. When I request the title of the game, 'name', I receive the name of the game but also 7 'undefined' outputs. Do you know why this is outputting those 'undefined' issues?

No Caption Provided

Avatar image for laika
laika

148

Forum Posts

1

Wiki Points

0

Followers

Reviews: 0

User Lists: 1

#4  Edited By laika

Make sure that you update the `field_list` parameter in the API request to include the genres and platforms. If you leave off that parameter entirely, you'll get a full response without the need to specify fields.

If you `console.log` the response, you can see a nicely detailed output of the response.

Avatar image for martijnotter
martijnotter

6

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#5  Edited By martijnotter

@laika: I only requested the `field_list` 'name' parameter. But I still get multiple responses. Not sure why this is possible because I don't see the responses in de json result.

I got `&field_list=name` in my link, no other parameters.

Avatar image for martijnotter
martijnotter

6

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

Never mind, found the solution. I was still looping the result. Thanks for the help.