The best way to parse a JSON in Dart

后端 未结 6 2020
温柔的废话
温柔的废话 2020-12-09 16:43

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:

            


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-09 16:52

    It depends on a lot of things.

    Is the json text you get is an array or a map?

    You can try with:

    Map model = new parse(response);
    

    Or

    List model = new parse(response);
    

    but you need to import JSONObject by Chris Buckett into your package

    import "package:json_object/json_object.dart";
    

    You can install it from pubspec adding this dependency

    json_object
    

提交回复
热议问题