我正在尝试将json对象发送到api端点。但我得到了以下信息:
I / flutter(28184): 200
I / flutter(28184): {"error": "the JSON object must be str, not 'bytes'"}
我尝试过以下几种方法:
Future<http.Response> sendPost() async{
var post = {
"profile_id" : "${_profile_id}",
"profile_name" : "${_profile_Name}",
"profile_country" : "${_profile_country}",
"post_id" : "${current_post_id}",
"post_image_id" : "${current_post_image}",
"post_desc" : "La La La La La La",
"post_likes" : "${post_likes}",
"post_timestamp" : "05-06-2019 22:34",
"post_comments" : [],
"post_comments_profile_name" : [],
"post_comments_profile_image_id" : [],
"post_comments_timestamp" : []
};
var body = utf8.encode(json.encode(post));
var addPost = await http.post(
url,
headers: {"content-type" : "application/json"},
body: body
);
print("${addPost.statusCode}");
print("${addPost.body}");
return addPost;
}
另外,当您回答时,请记住此Map中应该有空数组。
https://stackoverflow.com/questions/56139284
复制相似问题