how to send this parameters by using alamofire












0















I want to send these parameters by using Alamofire, but the problem is inside the parameters there is a String array called person. How do I convert it to a Dictionary to be able to send it?



Here are the parameters to send:



{
"BRANCH_ID" : 23,
"PACKAGE_ID": 10,
"ARRIVE_TIME_ID": 7,
"ARRIVE_DATE" : "12/2/2014",
"IS_TABLE" : true,
"IS_TICKET" : false,
"NOTE": "hi",
"persons": "[{
"ID":" 1",
"FIRST_NAME":"Ali",
"LAST_NAME":"Ahmed",
"GENDER":"Male",
"EMAIL":"mz_@.fgj",
"FACEBOOK_URL":"www.google.com",
"IS_MEMBER":"true",
"IS_BOOKER":"true"
}]",
"addons": ""
}


What I have so far:



let url = URLs.addPlaceBooking
let headers: HTTPHeaders = ["Content-type": "application/json"]
let paramters : [String : Any ] = [
"BRANCH_ID" : "23",
"PACKAGE_ID": "10",
"ARRIVE_TIME_ID": "12",
"ARRIVE_DATE" : "12/2/2014",
"IS_TABLE" : true,
"IS_TICKET" : false ,
"NOTE": "",
"persons" : [
"ID": "1",
"FIRST_NAME":"Ali",
"LAST_NAME":"Ahmed",
"GENDER":"Male",
"MOBILE":"0111281456",
"EMAIL":"mz_@.fgj",
"FACEBOOK_URL":"www.google.com",
"IS_MEMBER": true,
"IS_BOOKER": true],
"addons":
]
]

Alamofire.request(url, method: .post , parameters: paramters, encoding: URLEncoding.default , headers: headers).responseJSON { respons in
switch respons.result {
case .success(let value ): print(value)
case .failure(let error): print(error)
}
}









share|improve this question

























  • Could you also post what have you tried so far?

    – Ahmad F
    Jan 1 at 21:16











  • @AhmadF I have added

    – Sekiz
    Jan 1 at 21:21
















0















I want to send these parameters by using Alamofire, but the problem is inside the parameters there is a String array called person. How do I convert it to a Dictionary to be able to send it?



Here are the parameters to send:



{
"BRANCH_ID" : 23,
"PACKAGE_ID": 10,
"ARRIVE_TIME_ID": 7,
"ARRIVE_DATE" : "12/2/2014",
"IS_TABLE" : true,
"IS_TICKET" : false,
"NOTE": "hi",
"persons": "[{
"ID":" 1",
"FIRST_NAME":"Ali",
"LAST_NAME":"Ahmed",
"GENDER":"Male",
"EMAIL":"mz_@.fgj",
"FACEBOOK_URL":"www.google.com",
"IS_MEMBER":"true",
"IS_BOOKER":"true"
}]",
"addons": ""
}


What I have so far:



let url = URLs.addPlaceBooking
let headers: HTTPHeaders = ["Content-type": "application/json"]
let paramters : [String : Any ] = [
"BRANCH_ID" : "23",
"PACKAGE_ID": "10",
"ARRIVE_TIME_ID": "12",
"ARRIVE_DATE" : "12/2/2014",
"IS_TABLE" : true,
"IS_TICKET" : false ,
"NOTE": "",
"persons" : [
"ID": "1",
"FIRST_NAME":"Ali",
"LAST_NAME":"Ahmed",
"GENDER":"Male",
"MOBILE":"0111281456",
"EMAIL":"mz_@.fgj",
"FACEBOOK_URL":"www.google.com",
"IS_MEMBER": true,
"IS_BOOKER": true],
"addons":
]
]

Alamofire.request(url, method: .post , parameters: paramters, encoding: URLEncoding.default , headers: headers).responseJSON { respons in
switch respons.result {
case .success(let value ): print(value)
case .failure(let error): print(error)
}
}









share|improve this question

























  • Could you also post what have you tried so far?

    – Ahmad F
    Jan 1 at 21:16











  • @AhmadF I have added

    – Sekiz
    Jan 1 at 21:21














0












0








0








I want to send these parameters by using Alamofire, but the problem is inside the parameters there is a String array called person. How do I convert it to a Dictionary to be able to send it?



Here are the parameters to send:



{
"BRANCH_ID" : 23,
"PACKAGE_ID": 10,
"ARRIVE_TIME_ID": 7,
"ARRIVE_DATE" : "12/2/2014",
"IS_TABLE" : true,
"IS_TICKET" : false,
"NOTE": "hi",
"persons": "[{
"ID":" 1",
"FIRST_NAME":"Ali",
"LAST_NAME":"Ahmed",
"GENDER":"Male",
"EMAIL":"mz_@.fgj",
"FACEBOOK_URL":"www.google.com",
"IS_MEMBER":"true",
"IS_BOOKER":"true"
}]",
"addons": ""
}


What I have so far:



let url = URLs.addPlaceBooking
let headers: HTTPHeaders = ["Content-type": "application/json"]
let paramters : [String : Any ] = [
"BRANCH_ID" : "23",
"PACKAGE_ID": "10",
"ARRIVE_TIME_ID": "12",
"ARRIVE_DATE" : "12/2/2014",
"IS_TABLE" : true,
"IS_TICKET" : false ,
"NOTE": "",
"persons" : [
"ID": "1",
"FIRST_NAME":"Ali",
"LAST_NAME":"Ahmed",
"GENDER":"Male",
"MOBILE":"0111281456",
"EMAIL":"mz_@.fgj",
"FACEBOOK_URL":"www.google.com",
"IS_MEMBER": true,
"IS_BOOKER": true],
"addons":
]
]

Alamofire.request(url, method: .post , parameters: paramters, encoding: URLEncoding.default , headers: headers).responseJSON { respons in
switch respons.result {
case .success(let value ): print(value)
case .failure(let error): print(error)
}
}









share|improve this question
















I want to send these parameters by using Alamofire, but the problem is inside the parameters there is a String array called person. How do I convert it to a Dictionary to be able to send it?



Here are the parameters to send:



{
"BRANCH_ID" : 23,
"PACKAGE_ID": 10,
"ARRIVE_TIME_ID": 7,
"ARRIVE_DATE" : "12/2/2014",
"IS_TABLE" : true,
"IS_TICKET" : false,
"NOTE": "hi",
"persons": "[{
"ID":" 1",
"FIRST_NAME":"Ali",
"LAST_NAME":"Ahmed",
"GENDER":"Male",
"EMAIL":"mz_@.fgj",
"FACEBOOK_URL":"www.google.com",
"IS_MEMBER":"true",
"IS_BOOKER":"true"
}]",
"addons": ""
}


What I have so far:



let url = URLs.addPlaceBooking
let headers: HTTPHeaders = ["Content-type": "application/json"]
let paramters : [String : Any ] = [
"BRANCH_ID" : "23",
"PACKAGE_ID": "10",
"ARRIVE_TIME_ID": "12",
"ARRIVE_DATE" : "12/2/2014",
"IS_TABLE" : true,
"IS_TICKET" : false ,
"NOTE": "",
"persons" : [
"ID": "1",
"FIRST_NAME":"Ali",
"LAST_NAME":"Ahmed",
"GENDER":"Male",
"MOBILE":"0111281456",
"EMAIL":"mz_@.fgj",
"FACEBOOK_URL":"www.google.com",
"IS_MEMBER": true,
"IS_BOOKER": true],
"addons":
]
]

Alamofire.request(url, method: .post , parameters: paramters, encoding: URLEncoding.default , headers: headers).responseJSON { respons in
switch respons.result {
case .success(let value ): print(value)
case .failure(let error): print(error)
}
}






swift alamofire






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 0:06









S..

3,9802532




3,9802532










asked Jan 1 at 20:15









SekizSekiz

67




67













  • Could you also post what have you tried so far?

    – Ahmad F
    Jan 1 at 21:16











  • @AhmadF I have added

    – Sekiz
    Jan 1 at 21:21



















  • Could you also post what have you tried so far?

    – Ahmad F
    Jan 1 at 21:16











  • @AhmadF I have added

    – Sekiz
    Jan 1 at 21:21

















Could you also post what have you tried so far?

– Ahmad F
Jan 1 at 21:16





Could you also post what have you tried so far?

– Ahmad F
Jan 1 at 21:16













@AhmadF I have added

– Sekiz
Jan 1 at 21:21





@AhmadF I have added

– Sekiz
Jan 1 at 21:21












2 Answers
2






active

oldest

votes


















0














It seems that the issue is persons parameter is an array of dictionaries (each dictionary represents a person); Based on the paramters you implemented in your code:



let paramters : [String : Any ] = [
"BRANCH_ID" : "23",
"PACKAGE_ID": "10",
"ARRIVE_TIME_ID": "12",
"ARRIVE_DATE" : "12/2/2014",
"IS_TABLE" : true,
"IS_TICKET" : false ,
"NOTE": "",
"persons" : [ "ID": "1",
"FIRST_NAME":"Ali",
"LAST_NAME":"Ahmed",
"GENDER":"Male",
"MOBILE":"0111281456",
"EMAIL":"mz_@.fgj",
"FACEBOOK_URL":"www.google.com",
"IS_MEMBER": true,
"IS_BOOKER": true] ,
"addons":
]


you are implementing persons as a single dictionary instead of an array of dictionaries.



The fix is to declare person as an array which contains a single dictionary, as:



let paramters : [String : Any ] = [
"BRANCH_ID" : "23",
"PACKAGE_ID": "10",
"ARRIVE_TIME_ID": "12",
"ARRIVE_DATE" : "12/2/2014",
"IS_TABLE" : true,
"IS_TICKET" : false ,
"NOTE": "",
"persons" : [[ "ID": "1",
"FIRST_NAME":"Ali",
"LAST_NAME":"Ahmed",
"GENDER":"Male",
"MOBILE":"0111281456",
"EMAIL":"mz_@.fgj",
"FACEBOOK_URL":"www.google.com",
"IS_MEMBER": true,
"IS_BOOKER": true]] ,
"addons":
]



Aside note: it should be "parameters" instead of "paramters" 😉






share|improve this answer
























  • @Ahmed F thank for your answer but doesn't work

    – Sekiz
    Jan 1 at 21:42











  • @Sekiz would you explain what's the issue?

    – Ahmad F
    Jan 1 at 21:42











  • @Ahmed F when I did that request in postman works perfectly with this form "persons": "[{"ID":" 1","FIRST_NAME":"Ali", "LAST_NAME":"Ahmed","GENDER":"Male","EMAIL":"mz_@.fgj", "FACEBOOK_URL":"www.google.com", "IS_MEMBER":"true" , "IS_BOOKER":"true" }]". now I want to convert this persons array to be able to send it with the request by the way the array of persons is sting

    – Sekiz
    Jan 1 at 21:50











  • @Sekiz what I answered should it be the form you've been asked for... Try to change the encoding to JSONEncoding.default instead of URLEncoding.default.

    – Ahmad F
    Jan 2 at 0:14



















0














In the JSON, "person" has a string value, not an array of objects, and "addons" has a string value also. I don't think this is what you want, but here is how to get it in Swift.



let json: [String: Any] = ["BRANCH_ID": 23, "PACKAGE_ID": 10,
"ARRIVE_TIME_ID": 7,
"ARRIVE_DATE" : "12/2/2014",
"IS_TABLE" : true,
"IS_TICKET" : false,
"NOTE": "hi",
"persons": "[{ " + // <-- Multi-line string not array of objects
""ID":" "1", " +
""FIRST_NAME":"Ali", " +
""LAST_NAME":"Ahmed", " +
""GENDER":"Male", " +
""EMAIL":"mz_@.fgj", " +
""FACEBOOK_URL":"www.google.com", " +
""IS_MEMBER":"true", " +
""IS_BOOKER":"true" " +
"}]", // <-- end of Multi-line string
"addons": ""] // <-- String not array

let string = try! String(data: JSONSerialization.data(withJSONObject: json, options: .prettyPrinted), encoding: .utf8)!
print(string)





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998623%2fhow-to-send-this-parameters-by-using-alamofire%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    It seems that the issue is persons parameter is an array of dictionaries (each dictionary represents a person); Based on the paramters you implemented in your code:



    let paramters : [String : Any ] = [
    "BRANCH_ID" : "23",
    "PACKAGE_ID": "10",
    "ARRIVE_TIME_ID": "12",
    "ARRIVE_DATE" : "12/2/2014",
    "IS_TABLE" : true,
    "IS_TICKET" : false ,
    "NOTE": "",
    "persons" : [ "ID": "1",
    "FIRST_NAME":"Ali",
    "LAST_NAME":"Ahmed",
    "GENDER":"Male",
    "MOBILE":"0111281456",
    "EMAIL":"mz_@.fgj",
    "FACEBOOK_URL":"www.google.com",
    "IS_MEMBER": true,
    "IS_BOOKER": true] ,
    "addons":
    ]


    you are implementing persons as a single dictionary instead of an array of dictionaries.



    The fix is to declare person as an array which contains a single dictionary, as:



    let paramters : [String : Any ] = [
    "BRANCH_ID" : "23",
    "PACKAGE_ID": "10",
    "ARRIVE_TIME_ID": "12",
    "ARRIVE_DATE" : "12/2/2014",
    "IS_TABLE" : true,
    "IS_TICKET" : false ,
    "NOTE": "",
    "persons" : [[ "ID": "1",
    "FIRST_NAME":"Ali",
    "LAST_NAME":"Ahmed",
    "GENDER":"Male",
    "MOBILE":"0111281456",
    "EMAIL":"mz_@.fgj",
    "FACEBOOK_URL":"www.google.com",
    "IS_MEMBER": true,
    "IS_BOOKER": true]] ,
    "addons":
    ]



    Aside note: it should be "parameters" instead of "paramters" 😉






    share|improve this answer
























    • @Ahmed F thank for your answer but doesn't work

      – Sekiz
      Jan 1 at 21:42











    • @Sekiz would you explain what's the issue?

      – Ahmad F
      Jan 1 at 21:42











    • @Ahmed F when I did that request in postman works perfectly with this form "persons": "[{"ID":" 1","FIRST_NAME":"Ali", "LAST_NAME":"Ahmed","GENDER":"Male","EMAIL":"mz_@.fgj", "FACEBOOK_URL":"www.google.com", "IS_MEMBER":"true" , "IS_BOOKER":"true" }]". now I want to convert this persons array to be able to send it with the request by the way the array of persons is sting

      – Sekiz
      Jan 1 at 21:50











    • @Sekiz what I answered should it be the form you've been asked for... Try to change the encoding to JSONEncoding.default instead of URLEncoding.default.

      – Ahmad F
      Jan 2 at 0:14
















    0














    It seems that the issue is persons parameter is an array of dictionaries (each dictionary represents a person); Based on the paramters you implemented in your code:



    let paramters : [String : Any ] = [
    "BRANCH_ID" : "23",
    "PACKAGE_ID": "10",
    "ARRIVE_TIME_ID": "12",
    "ARRIVE_DATE" : "12/2/2014",
    "IS_TABLE" : true,
    "IS_TICKET" : false ,
    "NOTE": "",
    "persons" : [ "ID": "1",
    "FIRST_NAME":"Ali",
    "LAST_NAME":"Ahmed",
    "GENDER":"Male",
    "MOBILE":"0111281456",
    "EMAIL":"mz_@.fgj",
    "FACEBOOK_URL":"www.google.com",
    "IS_MEMBER": true,
    "IS_BOOKER": true] ,
    "addons":
    ]


    you are implementing persons as a single dictionary instead of an array of dictionaries.



    The fix is to declare person as an array which contains a single dictionary, as:



    let paramters : [String : Any ] = [
    "BRANCH_ID" : "23",
    "PACKAGE_ID": "10",
    "ARRIVE_TIME_ID": "12",
    "ARRIVE_DATE" : "12/2/2014",
    "IS_TABLE" : true,
    "IS_TICKET" : false ,
    "NOTE": "",
    "persons" : [[ "ID": "1",
    "FIRST_NAME":"Ali",
    "LAST_NAME":"Ahmed",
    "GENDER":"Male",
    "MOBILE":"0111281456",
    "EMAIL":"mz_@.fgj",
    "FACEBOOK_URL":"www.google.com",
    "IS_MEMBER": true,
    "IS_BOOKER": true]] ,
    "addons":
    ]



    Aside note: it should be "parameters" instead of "paramters" 😉






    share|improve this answer
























    • @Ahmed F thank for your answer but doesn't work

      – Sekiz
      Jan 1 at 21:42











    • @Sekiz would you explain what's the issue?

      – Ahmad F
      Jan 1 at 21:42











    • @Ahmed F when I did that request in postman works perfectly with this form "persons": "[{"ID":" 1","FIRST_NAME":"Ali", "LAST_NAME":"Ahmed","GENDER":"Male","EMAIL":"mz_@.fgj", "FACEBOOK_URL":"www.google.com", "IS_MEMBER":"true" , "IS_BOOKER":"true" }]". now I want to convert this persons array to be able to send it with the request by the way the array of persons is sting

      – Sekiz
      Jan 1 at 21:50











    • @Sekiz what I answered should it be the form you've been asked for... Try to change the encoding to JSONEncoding.default instead of URLEncoding.default.

      – Ahmad F
      Jan 2 at 0:14














    0












    0








    0







    It seems that the issue is persons parameter is an array of dictionaries (each dictionary represents a person); Based on the paramters you implemented in your code:



    let paramters : [String : Any ] = [
    "BRANCH_ID" : "23",
    "PACKAGE_ID": "10",
    "ARRIVE_TIME_ID": "12",
    "ARRIVE_DATE" : "12/2/2014",
    "IS_TABLE" : true,
    "IS_TICKET" : false ,
    "NOTE": "",
    "persons" : [ "ID": "1",
    "FIRST_NAME":"Ali",
    "LAST_NAME":"Ahmed",
    "GENDER":"Male",
    "MOBILE":"0111281456",
    "EMAIL":"mz_@.fgj",
    "FACEBOOK_URL":"www.google.com",
    "IS_MEMBER": true,
    "IS_BOOKER": true] ,
    "addons":
    ]


    you are implementing persons as a single dictionary instead of an array of dictionaries.



    The fix is to declare person as an array which contains a single dictionary, as:



    let paramters : [String : Any ] = [
    "BRANCH_ID" : "23",
    "PACKAGE_ID": "10",
    "ARRIVE_TIME_ID": "12",
    "ARRIVE_DATE" : "12/2/2014",
    "IS_TABLE" : true,
    "IS_TICKET" : false ,
    "NOTE": "",
    "persons" : [[ "ID": "1",
    "FIRST_NAME":"Ali",
    "LAST_NAME":"Ahmed",
    "GENDER":"Male",
    "MOBILE":"0111281456",
    "EMAIL":"mz_@.fgj",
    "FACEBOOK_URL":"www.google.com",
    "IS_MEMBER": true,
    "IS_BOOKER": true]] ,
    "addons":
    ]



    Aside note: it should be "parameters" instead of "paramters" 😉






    share|improve this answer













    It seems that the issue is persons parameter is an array of dictionaries (each dictionary represents a person); Based on the paramters you implemented in your code:



    let paramters : [String : Any ] = [
    "BRANCH_ID" : "23",
    "PACKAGE_ID": "10",
    "ARRIVE_TIME_ID": "12",
    "ARRIVE_DATE" : "12/2/2014",
    "IS_TABLE" : true,
    "IS_TICKET" : false ,
    "NOTE": "",
    "persons" : [ "ID": "1",
    "FIRST_NAME":"Ali",
    "LAST_NAME":"Ahmed",
    "GENDER":"Male",
    "MOBILE":"0111281456",
    "EMAIL":"mz_@.fgj",
    "FACEBOOK_URL":"www.google.com",
    "IS_MEMBER": true,
    "IS_BOOKER": true] ,
    "addons":
    ]


    you are implementing persons as a single dictionary instead of an array of dictionaries.



    The fix is to declare person as an array which contains a single dictionary, as:



    let paramters : [String : Any ] = [
    "BRANCH_ID" : "23",
    "PACKAGE_ID": "10",
    "ARRIVE_TIME_ID": "12",
    "ARRIVE_DATE" : "12/2/2014",
    "IS_TABLE" : true,
    "IS_TICKET" : false ,
    "NOTE": "",
    "persons" : [[ "ID": "1",
    "FIRST_NAME":"Ali",
    "LAST_NAME":"Ahmed",
    "GENDER":"Male",
    "MOBILE":"0111281456",
    "EMAIL":"mz_@.fgj",
    "FACEBOOK_URL":"www.google.com",
    "IS_MEMBER": true,
    "IS_BOOKER": true]] ,
    "addons":
    ]



    Aside note: it should be "parameters" instead of "paramters" 😉







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 1 at 21:34









    Ahmad FAhmad F

    17.1k104285




    17.1k104285













    • @Ahmed F thank for your answer but doesn't work

      – Sekiz
      Jan 1 at 21:42











    • @Sekiz would you explain what's the issue?

      – Ahmad F
      Jan 1 at 21:42











    • @Ahmed F when I did that request in postman works perfectly with this form "persons": "[{"ID":" 1","FIRST_NAME":"Ali", "LAST_NAME":"Ahmed","GENDER":"Male","EMAIL":"mz_@.fgj", "FACEBOOK_URL":"www.google.com", "IS_MEMBER":"true" , "IS_BOOKER":"true" }]". now I want to convert this persons array to be able to send it with the request by the way the array of persons is sting

      – Sekiz
      Jan 1 at 21:50











    • @Sekiz what I answered should it be the form you've been asked for... Try to change the encoding to JSONEncoding.default instead of URLEncoding.default.

      – Ahmad F
      Jan 2 at 0:14



















    • @Ahmed F thank for your answer but doesn't work

      – Sekiz
      Jan 1 at 21:42











    • @Sekiz would you explain what's the issue?

      – Ahmad F
      Jan 1 at 21:42











    • @Ahmed F when I did that request in postman works perfectly with this form "persons": "[{"ID":" 1","FIRST_NAME":"Ali", "LAST_NAME":"Ahmed","GENDER":"Male","EMAIL":"mz_@.fgj", "FACEBOOK_URL":"www.google.com", "IS_MEMBER":"true" , "IS_BOOKER":"true" }]". now I want to convert this persons array to be able to send it with the request by the way the array of persons is sting

      – Sekiz
      Jan 1 at 21:50











    • @Sekiz what I answered should it be the form you've been asked for... Try to change the encoding to JSONEncoding.default instead of URLEncoding.default.

      – Ahmad F
      Jan 2 at 0:14

















    @Ahmed F thank for your answer but doesn't work

    – Sekiz
    Jan 1 at 21:42





    @Ahmed F thank for your answer but doesn't work

    – Sekiz
    Jan 1 at 21:42













    @Sekiz would you explain what's the issue?

    – Ahmad F
    Jan 1 at 21:42





    @Sekiz would you explain what's the issue?

    – Ahmad F
    Jan 1 at 21:42













    @Ahmed F when I did that request in postman works perfectly with this form "persons": "[{"ID":" 1","FIRST_NAME":"Ali", "LAST_NAME":"Ahmed","GENDER":"Male","EMAIL":"mz_@.fgj", "FACEBOOK_URL":"www.google.com", "IS_MEMBER":"true" , "IS_BOOKER":"true" }]". now I want to convert this persons array to be able to send it with the request by the way the array of persons is sting

    – Sekiz
    Jan 1 at 21:50





    @Ahmed F when I did that request in postman works perfectly with this form "persons": "[{"ID":" 1","FIRST_NAME":"Ali", "LAST_NAME":"Ahmed","GENDER":"Male","EMAIL":"mz_@.fgj", "FACEBOOK_URL":"www.google.com", "IS_MEMBER":"true" , "IS_BOOKER":"true" }]". now I want to convert this persons array to be able to send it with the request by the way the array of persons is sting

    – Sekiz
    Jan 1 at 21:50













    @Sekiz what I answered should it be the form you've been asked for... Try to change the encoding to JSONEncoding.default instead of URLEncoding.default.

    – Ahmad F
    Jan 2 at 0:14





    @Sekiz what I answered should it be the form you've been asked for... Try to change the encoding to JSONEncoding.default instead of URLEncoding.default.

    – Ahmad F
    Jan 2 at 0:14













    0














    In the JSON, "person" has a string value, not an array of objects, and "addons" has a string value also. I don't think this is what you want, but here is how to get it in Swift.



    let json: [String: Any] = ["BRANCH_ID": 23, "PACKAGE_ID": 10,
    "ARRIVE_TIME_ID": 7,
    "ARRIVE_DATE" : "12/2/2014",
    "IS_TABLE" : true,
    "IS_TICKET" : false,
    "NOTE": "hi",
    "persons": "[{ " + // <-- Multi-line string not array of objects
    ""ID":" "1", " +
    ""FIRST_NAME":"Ali", " +
    ""LAST_NAME":"Ahmed", " +
    ""GENDER":"Male", " +
    ""EMAIL":"mz_@.fgj", " +
    ""FACEBOOK_URL":"www.google.com", " +
    ""IS_MEMBER":"true", " +
    ""IS_BOOKER":"true" " +
    "}]", // <-- end of Multi-line string
    "addons": ""] // <-- String not array

    let string = try! String(data: JSONSerialization.data(withJSONObject: json, options: .prettyPrinted), encoding: .utf8)!
    print(string)





    share|improve this answer




























      0














      In the JSON, "person" has a string value, not an array of objects, and "addons" has a string value also. I don't think this is what you want, but here is how to get it in Swift.



      let json: [String: Any] = ["BRANCH_ID": 23, "PACKAGE_ID": 10,
      "ARRIVE_TIME_ID": 7,
      "ARRIVE_DATE" : "12/2/2014",
      "IS_TABLE" : true,
      "IS_TICKET" : false,
      "NOTE": "hi",
      "persons": "[{ " + // <-- Multi-line string not array of objects
      ""ID":" "1", " +
      ""FIRST_NAME":"Ali", " +
      ""LAST_NAME":"Ahmed", " +
      ""GENDER":"Male", " +
      ""EMAIL":"mz_@.fgj", " +
      ""FACEBOOK_URL":"www.google.com", " +
      ""IS_MEMBER":"true", " +
      ""IS_BOOKER":"true" " +
      "}]", // <-- end of Multi-line string
      "addons": ""] // <-- String not array

      let string = try! String(data: JSONSerialization.data(withJSONObject: json, options: .prettyPrinted), encoding: .utf8)!
      print(string)





      share|improve this answer


























        0












        0








        0







        In the JSON, "person" has a string value, not an array of objects, and "addons" has a string value also. I don't think this is what you want, but here is how to get it in Swift.



        let json: [String: Any] = ["BRANCH_ID": 23, "PACKAGE_ID": 10,
        "ARRIVE_TIME_ID": 7,
        "ARRIVE_DATE" : "12/2/2014",
        "IS_TABLE" : true,
        "IS_TICKET" : false,
        "NOTE": "hi",
        "persons": "[{ " + // <-- Multi-line string not array of objects
        ""ID":" "1", " +
        ""FIRST_NAME":"Ali", " +
        ""LAST_NAME":"Ahmed", " +
        ""GENDER":"Male", " +
        ""EMAIL":"mz_@.fgj", " +
        ""FACEBOOK_URL":"www.google.com", " +
        ""IS_MEMBER":"true", " +
        ""IS_BOOKER":"true" " +
        "}]", // <-- end of Multi-line string
        "addons": ""] // <-- String not array

        let string = try! String(data: JSONSerialization.data(withJSONObject: json, options: .prettyPrinted), encoding: .utf8)!
        print(string)





        share|improve this answer













        In the JSON, "person" has a string value, not an array of objects, and "addons" has a string value also. I don't think this is what you want, but here is how to get it in Swift.



        let json: [String: Any] = ["BRANCH_ID": 23, "PACKAGE_ID": 10,
        "ARRIVE_TIME_ID": 7,
        "ARRIVE_DATE" : "12/2/2014",
        "IS_TABLE" : true,
        "IS_TICKET" : false,
        "NOTE": "hi",
        "persons": "[{ " + // <-- Multi-line string not array of objects
        ""ID":" "1", " +
        ""FIRST_NAME":"Ali", " +
        ""LAST_NAME":"Ahmed", " +
        ""GENDER":"Male", " +
        ""EMAIL":"mz_@.fgj", " +
        ""FACEBOOK_URL":"www.google.com", " +
        ""IS_MEMBER":"true", " +
        ""IS_BOOKER":"true" " +
        "}]", // <-- end of Multi-line string
        "addons": ""] // <-- String not array

        let string = try! String(data: JSONSerialization.data(withJSONObject: json, options: .prettyPrinted), encoding: .utf8)!
        print(string)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 0:42









        Jeffery ThomasJeffery Thomas

        36.1k672102




        36.1k672102






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998623%2fhow-to-send-this-parameters-by-using-alamofire%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            Npm cannot find a required file even through it is in the searched directory

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith