3

How to post below json array?

"LstUserOptions": [
  {
    "OptionID": "ca339e40-10cc-4459-b9ec-07f7df0f4c69"
  }
]
3
  • Please add additional information to add some context to your question, including an attempt to solve the problem, which help us to better understand what you want. Commented Oct 26, 2018 at 6:15
  • How to post below json array? means what Commented Oct 26, 2018 at 6:23
  • I want to post that json array data in flutter body http.Response response = await http.post( Uri.encodeFull(ConfigApi.SAVE), body: body, headers: {'Content-type': 'application/json'}); Commented Oct 26, 2018 at 6:39

2 Answers 2

16

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;
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

u r awesome bro. i was searching for this thing 'Content-type': 'application/json'
it worked in my case too.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.