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

Time:01-09

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.

CodePudding user response:

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