Home > Back-end >  How would I use JSON formatted as such with flutter? Help working with the Gamebanana api
How would I use JSON formatted as such with flutter? Help working with the Gamebanana api

Time:12-19

The Gamebanana api returns data as such for https://api.gamebanana.com/Core/Item/Data?itemtype=Mod&itemid=350538&fields=name,description,Url().sDownloadUrl()&help=

[
    "Cloudrip",
    "Bair Force 1",
    "https:\/\/gamebanana.com\/mods\/download\/350538"
]

I have never seen json formatted in this way and I have no clue how to map it to things in flutter which uses:

fromJson(Map<String, dynamic> json)

Is the api just bad, or am I stupid and there is an easy way to work with this data? Thanks and sorry if this is really trivial as i'm incredibly inexperienced with web stuff.

I tried using the json as an array and getting elements from it that way but i get a Format exception saying that it isn't valid JSON.

CodePudding user response:

So first thing you need to recognize is that this is a list of string objects, so what you want to do is to treat it like that.

You don't need a model class just pull your data as a list for Strings and render them like that.

Your code should look something like this

  final Iterable  rawGameBananaData = jsonDecode(rawdata.body);
  return rawGameBananaData.map((e) => e).toList();

Now you have a list you can manipulate any which way you want in dart.

  • Related