JSON

将字符串转换为对象:

import 'dart:convert' show json;
var jsonString = '''
[
  {"score": 40},
  {"score": 80}
]
''';
var scores = json.decode(jsonString);
assert(scores is List);
assert(scores[0] is Map);
assert(firstScore['score'] == 40);
print(scores); // [{score: 40}, {score: 80}]

将对象转换为字符串:

var scores = [
  {'score': 40},
  {'score': 80},
];
var jsonText = json.encode(scores);
print(jsonText); // [{"score":40},{"score":80}]

MIT Licensed | Copyright © 2018-present 滇ICP备16006294号

Design by Quanzaiyu | Power by VuePress