Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

html - The best way to parse a JSON in Dart

I'm trying to load a json file from a URL and parse it within Dart. So I had tried the following code as suggested from some links when I google for it:

   HttpRequest.getString("hellknight2.js").then((response)
   {
     var model = new JSON.parse(response);
   });

However, it seems to not work anymore on Dart SDK version 0.4.3.5_r20602. What is the current best way to get a Json file mapped to an object in Dart?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Simply use json of the dart:convert package. Here is an example :

import 'dart:convert';

main() {
  final myJsonAsString = '{"a": 1, "b": "c"}';
  final decoded = json.decode(myJsonAsString);
  ....
}

See Parsing JSON for more details.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...