美文网首页
flutter json解析

flutter json解析

作者: 王保全_1098 | 来源:发表于2018-11-20 12:09 被阅读0次
  • 导入库文件:
    import 'dart:convert' show json;
  • 数组解析:
    ['foo', { 'bar': 499 }]
Map data= json.decode(response);
data[1]['bar'];
Map data= json.decode(response);
var url1= data['current_user_url'];

*实例:

getToken() async {
    Dio dio = new Dio();
    dio.options.baseUrl = ServerUrl.base;
    FormData formData = new FormData.from({
      "mobile": "13981981111",
      "pwd": "983532",
    });
    Response response = await dio.post(ServerUrl.token, data: formData);
    String result = "{\"status\": 0, \"description\": \"success\", \"data\": {\"token\": \"eyJhbGciOiJIUzI1NiJ9.eyJtZW1pZCI6IjEzOTgxOTgzNTMyIiwiY29tcGFueV9pZCI6MjAxNzExMjQzLCJleHAiOjE1NDUyODA5MjB9.3RnJR1i70jD1TUpDn52UTgOrqhhXRZpvS9yMMTD4G74\"}, \"extra\": {\"ssize\": 1, \"snow\": 1542688920, \"other\": null}}";//response.data.toString();
    print(result);
    Map resultMap = json.decode(result);
    String token = resultMap["data"]["token"];
    print(token);
  }

相关文章

网友评论

      本文标题:flutter json解析

      本文链接:https://www.haomeiwen.com/subject/jjitqqtx.html