1

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?

3
  • could you include your api code too? Commented Dec 8, 2022 at 7:57
  • added the api calling part Commented Dec 8, 2022 at 8:03
  • go through this docs.flutter.dev/cookbook/networking/send-data to learn how to send data to server Commented Dec 8, 2022 at 8:11

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for the update i have 1 question how should i pass the data for an array for example "text_animation":[ { "source":"templates", "type":"start" }, { "source":"templates", "type":"start" } ] for and array how can i pass multiple objects should i create a loop or pass array with key? really appriciate
@tushar you can store that array in var like` var data = list of array` and in the map you can add it like map = {"text_animation":json.encode(data)} and you can add this map into body and you are good to go
thanks you once again

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.