simc / crimson

Fast, efficient and easy-to-use JSON parser and serializer for Dart.
Apache License 2.0
229 stars 6 forks source link

Unable to locate how to use fromJson in readme #19

Closed dhirajhimani closed 1 year ago

dhirajhimani commented 1 year ago

` static final Map<String, dynamic> userMeResponse = jsonDecode(''' { "me": { "id": "some-id", "firstName": "erst", "lastName": "zwei" } }''';

`

How to read the Map<String, dynamic> as from Json. final crimson = Crimson(utf8.encode(userMeResponse)); print (crimson.read()); final xyz = crimson.readXYZ();

Please could you provide a sample where Map<String, dynamic> is being read and consumed by Crimson

arcas0803 commented 1 year ago

I discover how to do it. You need to write your own method to get Object from Map<String, dynamic>

factory Mascota.fromBytes(Uint8List json) => _$MascotaFromBytes(json);

factory Mascota.frmJson(Map<String, dynamic> json) => Mascota.fromBytes(
        Uint8List.fromList(
          jsonEncode(json).codeUnits,
        ),
      );