Skip to content

Instantly share code, notes, and snippets.

@keima
Created January 11, 2023 11:18
Show Gist options
  • Save keima/8ba750b7aafac714b293b1b89c1ad5ed to your computer and use it in GitHub Desktop.
Save keima/8ba750b7aafac714b293b1b89c1ad5ed to your computer and use it in GitHub Desktop.
/*
output:
JSArray<dynamic>
[{id: 1, name: John}, {id: 2, name: Jane}, {id: 3, name: Joseph}]
_JsonMap
{id: 1, name: John}
1
John
---
true
true
false
---
false
false
true
true
false
*/
import 'dart:convert';
void main() {
final jsonString = r'''[
{"id": "1", "name": "John"},
{"id": "2", "name": "Jane"},
{"id": "3", "name": "Joseph"}
]''';
final x = jsonDecode(jsonString);
print(x.runtimeType);
print(x);
print(x[0].runtimeType);
print(x[0]);
print(x[0]['id']);
print(x[0]['name']);
print("---");
print(x is List);
print(x is Iterable);
print(x is Map);
print("---");
print(x[0] is List);
print(x[0] is Iterable);
print(x[0] is Map);
print(x[0] !is Map); // force unwrap
print(x[0] is! Map);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment