【问题标题】:How to use Get method in dart? [closed]如何在飞镖中使用Get方法? [关闭]
【发布时间】:2021-12-04 12:17:01
【问题描述】:

如何在 dart 中使用 Get 方法,然后将 json(从服务器返回)解码为变量? 有什么例子吗?

【问题讨论】:

    标签: android json flutter dart postman


    【解决方案1】:

    使用 http & convert 包轻松完成: htttpconvert

     import 'dart:convert' as convert;
     import 'package:http/http.dart' as http;
     var url =
          Uri.https('your url', 'apiEndPoint', {'queryParameter': '{queryValue}'});
    
      // Await the http get response, then decode the json-formatted response.
      var response = await http.get(url);
      if (response.statusCode == 200) {
        var jsonResponse =
            convert.jsonDecode(response.body) as Map<String, dynamic>;
        var item = jsonResponse['itemName'];
        print('Item is : $item.');
      } else {
        print('Request failed with status: ${response.statusCode}.');
      }
    

    【讨论】:

      猜你喜欢
      • 2021-12-05
      • 2013-05-19
      • 2020-11-28
      • 1970-01-01
      • 2021-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多