How to post a data using dio to an array wrapped inside a json and inside that array is also a json

huangapple go评论61阅读模式
英文:

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),);

huangapple
  • 本文由 发表于 2023年1月9日 19:54:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75056900.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定