lemuriyan
lemuriyan

Reputation: 606

Flutter how to post json array

How to post below json array?

"LstUserOptions": [
  {
    "OptionID": "ca339e40-10cc-4459-b9ec-07f7df0f4c69"
  }
]

Upvotes: 3

Views: 14959

Answers (2)

user11008199
user11008199

Reputation:

how to done this work with dio package i send whole my data with dio and now i want send a array of json with it , is correct this code if assume my json array is body

FormData formData = new FormData.from({
"cars": body
});
response = await dio.post("url", data: 
formData);

Upvotes: 0

lemuriyan
lemuriyan

Reputation: 606

i found the solution :

List<Map> carOptionJson = new List();
CarJson carJson = new CarJson("ca339e40-10cc-4459-b9ec-07f7df0f4c69");
carOptionJson.add(carJson.TojsonData());

var body = json.encode({
  "LstUserOptions": carOptionJson
});

http.Response response = await http.post(
    Uri.encodeFull(ConfigApi.SAVE),
    body: body,
    headers: {'Content-type': 'application/json'});

class CarJson {
  String OptionID;
  CarJson(this.OptionID);
  Map<String, dynamic> TojsonData() {
    var map = new Map<String, dynamic>();
    map["OptionID"] = OptionID;
    return map;
  }
}

Upvotes: 16

Related Questions