Reputation: 36
I want to send data to my API URL. How to post below JSON?
for the moment im using http method to call the api but the main issue im facing is to post the json below any other method or easy way, i can use to call api other than http The data I want to send is this:
api calling part
var url1 = http.get(
Uri.parse(
'url'),
headers: {"Authorization": "access"});
{
"audio": {},
"output": {
"width": 110,
"height": 110,
"format": "mp4",
"name": "video",
"title": "video",
"description": ""
},
"scenes": [
{
"background": {
"src": [
{
"url": "",
"asset_id": "",
"type": "video",
}
],
"bg_animation": {
"animation": ""
}
},
"time": 7.42,
"keywords": [],
"sub_scenes": [
{
"time": 0.88,
"location": {
"center_x": 360,
"end_y": 1190.3999999999999,
"start_y": 1131.625
},
"text_lines": [
{
"text_animation": [
{
"source": "templates",
"type": "start",
}
],
"text_bg_animation": [
{
"source": "templates",
"type": "start",
}
],
"text": "Six websites. To"
}
],
"subtitle": "",
"font": {
"name": "Helvetica.ttf",
"size": "26",
}
}
],
"sentences": [
{
"time": 0.88,
"text": "Six websites. To"
}
],
"music": false,
"tts": false,
"subtitle": true
}
],
"projectId":
}
Now I have an error about Invalid Argument because I don't know how to send a JSON array. Can anyone help me?
Upvotes: 1
Views: 421
Reputation: 570
Create a Map and send it using json.encode(Name of the map)
For example Map<dynamic,dynamic> map = new Map();
map = {
"audio":{
},
"output":{
"width":110,
"height":110,
"format":"mp4",
"name":"video",
"title":"video",
"description":""
},
"scenes":[
{
"background":{
"src":[
{
"url":"",
"asset_id":"",
"type":"video"
}
],
"bg_animation":{
"animation":""
}
},
"time":7.42,
"keywords":[
],
"sub_scenes":[
{
"time":0.88,
"location":{
"center_x":360,
"end_y":1190.3999999999999,
"start_y":1131.625
},
"text_lines":[
{
"text_animation":[
{
"source":"templates",
"type":"start"
}
],
"text_bg_animation":[
{
"source":"templates",
"type":"start"
}
],
"text":"Six websites. To"
}
],
"subtitle":"",
"font":{
"name":"Helvetica.ttf",
"size":"26"
}
}
],
"sentences":[
{
"time":0.88,
"text":"Six websites. To"
}
],
"music":false,
"tts":false,
"subtitle":true
}
],
"projectId":""
}
then in you body send it like {"data" : json.encode(map)};
Note: Not the perfect syntax but you will probably get a rough idea.
Upvotes: 1