Whats the best way to do this? The solution I found right now is pretty crappy?
http.Response resp = await http.get('$endpoint');
List l = json.decode(resp.body);
List<Message> c = new List();
l.forEach((i){
c.add(new Message.fromJson(i));
return i;
});
return c;
import 'dart:convert';
main() async {
var stuff;
var myThing = (JSON.decode(stuff) as List).map((e) => new MyClass.fromJson(e)).toList();
}
Doesn't it make sense to have this method part of the library, so that you can pass in a Map or a List to fromJson?
It's just a lot of repeated code if you have a large api that returns JSONArrays for each of it's calls.
Agreed.
On Thu, Apr 12, 2018 at 7:52 AM Faisal Abid notifications@github.com
wrote:
Doesn't it make sense to have this method part of the library, so that you
can pass in a Map or a List to fromJson?It's just a lot of repeated code if you have a large api that returns
JSONArrays for each of it's calls.—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
https://github.com/dart-lang/json_serializable/issues/135#issuecomment-380833594,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABCikf7QPSyNpywb85PKJS5AUZj94VZks5tn2oQgaJpZM4TRE2Q
.
to add to that, does it also make sense to do a json.decode(). why not just pass the json string and let json_serializeable deal with it?
for example
MyClass c = new MyClass.fromJson(responsePayloadFromServer);
Neat and clean
You can serialize as follows:
List<Obj> (jsonDecode(value) as List).map((f) => Obj.fromJson(f)).toList();
I hope I helped because it seems that the serializations shown are out of date.
Most helpful comment