I'm trying to load a json file from a URL and parse it within Dart. So I had tried the following code as suggested from some links when I google for it:
HttpRequest.getString("hellknight2.js").then((response)
{
var model = new JSON.parse(response);
});
However, it seems to not work anymore on Dart SDK version 0.4.3.5_r20602. What is the current best way to get a Json file mapped to an object in Dart?
There's a new pub package for this:
Victor Savkin - Serializers.
I didn't use it but seems to me that it will suite you. Try it out
It depends on a lot of things.
Is the json text you get is an array or a map?
You can try with:
Or
but you need to import JSONObject by Chris Buckett into your package
You can install it from pubspec adding this dependency
Simply use json of the
dart:convert
package. Here is an example :See Parsing JSON for more details.
here is my solution :) At first you need to import :
then you can get values by key, like belowe:
in my case
didn't work.
Instead I had to use :