json - 使用嵌套 JSON 作为数据 + BLoC 模式的 Flutter Post 请求
问题描述
我尝试使用 BLoC 模式在 Post Request 中传递 JSON。
jsonEncode(<String, String>{
'MobileNo': _emailController.value,
'Password': _passwordController.value,
'IPAddress': '192.168.0.1',
'Latitude' : '23.04503',
'Longitude': '72.55919',
"wauid" : 'd4KY17YySLC8-ROzs1RoJN:APA91bHMVz-4tw7cRIrEmBU2wHr_YW1RgV5HQfcfQp1YQwkamDPUimiPrfisezPuOgghJgHepXixsRh1Rl_eu75E9qss4RzxM6bGIgQdSo-S9TvynJsfdztz67LiaWbC9fs4xlCZnFQc'
});
我找到了使用jsonEncode传递 JSON 的所有解决方案,但我没有找到任何在 Flutter 的 Post Request 中传递嵌套 JSON 的解决方案。
这是我传递的 JSON:
{
"userMaster": {
"MobileNo": "8800112233",
"Password": "564452",
"Latitude": 23.04503,
"Longitude": 72.55919,
"IPAddress": "5f7f51e7-09f5-4cf2-87f3-ca5760f1ed57",
"wauid": "12312"
},
"loginInfo" : {
"UserID":0
}
}
谁能告诉我如何发送嵌套的 JSON 来发布 Flutter 的请求?
解决方案
请在下面尝试
Map<String, dynamic> payload = {
"userMaster": {
"MobileNo": "8800112233",
"Password": "564452",
"Latitude": 23.04503,
"Longitude": 72.55919,
"IPAddress": "5f7f51e7-09f5-4cf2-87f3-ca5760f1ed57",
"wauid": "12312"
},
"loginInfo" : {
"UserID":0
}
}
Response response = await http.post(<URL>,body: json.encode(payload));
推荐阅读
- sas - 热图 SAS 一些标签加粗
- javascript - 防止 toFixed 舍入非常小的十进制数
- javascript - 未捕获的 TypeError:PouchDB 不是构造函数
- android - 处理物品的正确方法点击回收站视图
- ms-access - 在 ms 访问表单中,如何根据两个文本框的值进行搜索?
- angular - 在 catchError (RxJS) 上意外调用HaveBeen
- excel - How to open up a new Excel Workbook in MS Access VBA that's of the newer format?
- c# - 如何在循环中跳过我在循环中得到的索引
- r - 收集列表中的所有缩进行
- excel - excel公式搜索多个条件