Http 类型'_内部链接dhashmap<;字符串,动态>';不是类型为';字符串';在颤振中使用MultipartRequest的类型内浇铸
我正试图通过以下主体发送POST请求:Http 类型'_内部链接dhashmap<;字符串,动态>';不是类型为';字符串';在颤振中使用MultipartRequest的类型内浇铸,http,flutter,dart,xmlhttprequest,dart-pub,Http,Flutter,Dart,Xmlhttprequest,Dart Pub,我正试图通过以下主体发送POST请求: { name_en: TV, name_ar: تلفزز, description_en: Big TV, description_ar: للفو, price_cents: 14300, discount_price_cents: null, sub_category_id: 2, quantity: 12, status: available, featured: false, gender_
{
name_en: TV,
name_ar: تلفزز,
description_en: Big TV,
description_ar: للفو,
price_cents: 14300,
discount_price_cents: null,
sub_category_id: 2,
quantity: 12,
status: available,
featured: false,
gender_compatibility: any,
seller_id: 2,
stocks: {
color_id: 2,
size_id: 2,
stock_quantity: 11
}
}
但我一直收到上面的错误。我知道这个错误是因为请求中嵌套了“stocks”,但是我还没有找到一种方法来解析它并使它工作
以下是代码块:
var uri = Uri.parse(
'${Constants.kHostUrl}$url?auth_key=${Constants.kAUTH_KEY}');
var request = http.MultipartRequest('POST', uri);
request.fields.addAll(object.cast<String, String>());
request.files.add(await http.MultipartFile.fromPath('image', image));
var response = await request.send();
var uri=uri.parse(
“${Constants.khostrl}$url?auth_key=${Constants.kAUTH_key}”);
var request=http.MultipartRequest('POST',uri);
request.fields.addAll(object.cast());
add(等待http.MultipartFile.fromPath('image',image));
var response=wait request.send();
错误发生在
request.fields.addAll(object.cast())代码>您的地图包含不同类型的对象,如字符串、数字和布尔值,因此不能将其强制转换为包含字符串。@julemand101当我将对象类型设置为动态时,如果没有“stocks”对象,代码可以正常工作。但是“stocks”的问题是它包含其他对象。为什么不将地图转换为JSON并将JSON字符串发送到web服务?@julemand101我尝试使用jsonecode
转换它,但随后使用字段。addAll
向我提供类型“string”不是类型“Map”的子类型
确定,但是这个API是如何工作的呢?请求中的字段只能是映射字段,因此您需要了解如何表示stocks字段。也许它应该是JSON格式的?您的映射包含不同类型的对象,如字符串、数字和布尔值,因此不能仅强制转换为包含字符串。@julemand101当我将对象类型设置为动态时,没有“stocks”对象,代码可以正常工作。但是“stocks”的问题是它包含其他对象。为什么不将地图转换为JSON并将JSON字符串发送到web服务?@julemand101我尝试使用jsonecode
转换它,但随后使用字段。addAll
向我提供类型“string”不是类型“Map”的子类型
确定,但是这个API是如何工作的呢?请求中的字段只能是映射字段,因此您需要了解如何表示stocks字段。也许它应该是JSON格式的?