英文:
How to post a data using dio to an array wrapped inside a json and inside that array is also a json
问题
如何使用dio将数据发布到包含在json内部的数组,并且该数组内部还包含一个json。响应的结构如下:
{
"result":[
{
"title":"String",
"caption":"String",
"related":[
{
"relatedTitle":"String",
"relatedCaption":"String"
}
]
}
]
}
我想要将值发布到"related"键内的"relatedTitle"和"relatedCaption"。请帮助解决这个问题。
英文:
How to post a data using dio to an array wrapped inside a json and inside that array is also a json. the structure of response is like below :
{
"result":[
{
"title":"String",
"caption":"String"
"related":[
{
"relatedTitle":"String",
"relatedCaption":"String"
}
]
}
]
}
I want to post value to the relatedTitle and relatedCaption inside the related key.
Please help out in it.
答案1
得分: 1
var body = {
"title": "String",
"caption": "String",
"related": [
{
"relatedTitle": "String",
"relatedCaption": "String"
}
]
};
var response = await dio.post(Url, data: jsonEncode(body),);
英文:
> try to encode your json like:
var body = {
"title":"String",
"caption":"String",
"related":[
{
"relatedTitle":"String",
"relatedCaption":"String"
}
]
};
var response = await dio.post(Url, data: jsonEncode(body),);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论