如何连接字符串和获取数据波动

问题描述 投票:0回答:1

我在api调用中遇到问题,我获取了当前位置的地理位置,我正在传递纬度和经度但是我有一个问题是我需要将纬度和经度传递给像lat_11.3054724$75.8744252这样的某些格式,所以我不能尝试将$符号和它一起加上,[]

Json值从api返回

{
  "msg": "Exist",
  "bannerapp": [
    {
      "app_banners": "uploads\/banner\/app\/banner-1.jpg"
    },
    {
      "app_banners": "uploads\/banner\/app\/banner-1.jpg"
    },
    {
      "app_banners": "uploads\/banner\/app\/banner-1.jpg"
    },
    {
      "app_banners": "uploads\/banner\/app\/banner-1.jpg"
    }
  ]
}

代码

   Future<String> getMainbanner() async {

          var latitude=_currentPosition.latitude.toString();
          var longitude=_currentPosition.longitude.toString();

        var response = await http.post(Urls.HOME_BANNER,
            headers: {"Content-Type": "application/json"},
            body: json.encode({
              "banner_type": "Main_Banner",
              "location": "lat_"+latitude+'$'+longitude,
            }),);
        Map<String, dynamic> value = json.decode(response.body);
        if (response.statusCode == 200) {
          var resp = response.body;
          Map<String, dynamic> value = json.decode(resp);
          var message = value['msg'];
          var banner =value['bannerapp'][0];

          for (int i = 0; i < banner.length; i++) {
            var data = banner[i];

            print("Data:"+data);

          }

        }
        else
          {
            CustomDialogs().showErrorAlert(context, "Main Banner Image NotFound");
          }
      }
    
<<

问题是美元。 $是dart中用于插入字符串的特殊字符,因此必须在其之前添加转义\。

flutter dart flutter-layout
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.