KAMALESH G
KAMALESH G

Reputation: 3

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. 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.

Upvotes: 0

Views: 1093

Answers (1)

Mahmoud Ahmed
Mahmoud Ahmed

Reputation: 125

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

Upvotes: 1

Related Questions