Skip to content

Commit

Permalink
Added the JSON file with JsonObject and JsonArray classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
shinayser committed Feb 13, 2019
1 parent dabce33 commit bf9653c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/utils/json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class JsonObject extends DelegatingMap<String, dynamic> {
JsonEncoder encoder = JsonEncoder.withIndent(' ');
return encoder.convert(jsonMap);
}

dynamic operator [](Object key) {
var value = delegate[key];
if (value is Map<String, dynamic>) return JsonObject(value);
if (value is List<dynamic>) return JsonArray.list(value);
return value;
}
}

class JsonArray<T> extends DelegatingList<T> {
Expand All @@ -29,7 +36,6 @@ class JsonArray<T> extends DelegatingList<T> {
List<dynamic> array = (json.decode(jsonString));

try {
//Tries to convert the members into JsonObjects
final auxArray = array.map((value) => JsonObject(value)).toList();
array = auxArray;
} catch (e) {}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: shinayser_essentials_flutter
description: A new Flutter project.
version: 1.1.2
version: 1.1.3
author:
homepage:

Expand Down

0 comments on commit bf9653c

Please sign in to comment.