Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/JSON/Dart/json-1.dart
Normal file
30
Task/JSON/Dart/json-1.dart
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import 'dart:convert' show jsonDecode, jsonEncode;
|
||||
|
||||
main(){
|
||||
var json_string = '''
|
||||
{
|
||||
"rosetta_code": {
|
||||
"task": "json",
|
||||
"language": "dart",
|
||||
"descriptions": [ "fun!", "easy to learn!", "awesome!" ]
|
||||
}
|
||||
}
|
||||
''';
|
||||
|
||||
// decode string into Map<String, dynamic>
|
||||
var json_object = jsonDecode(json_string);
|
||||
|
||||
for ( var description in json_object["rosetta_code"]["descriptions"] )
|
||||
print( "dart is $description" );
|
||||
|
||||
var dart = {
|
||||
"compiled": true,
|
||||
"interpreted": true,
|
||||
"creator(s)":[ "Lars Bak", "Kasper Lund"],
|
||||
"development company": "Google"
|
||||
};
|
||||
|
||||
var as_json_text = jsonEncode(dart);
|
||||
|
||||
assert(as_json_text == '{"compiled":true,"interpreted":true,"creator(s)":["Lars Bak","Kasper Lund"],"development company":"Google"}');
|
||||
}
|
||||
9
Task/JSON/Dart/json-2.dart
Normal file
9
Task/JSON/Dart/json-2.dart
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import 'dart:convert';
|
||||
|
||||
main(){
|
||||
var data = jsonDecode('{ "foo": 1, "bar": [10, "apples"] }');
|
||||
|
||||
var sample = { "blue": [1,2], "ocean": "water" };
|
||||
|
||||
var json_string = jsonEncode(sample);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue