my api expects to receive JSON data in below form
{
"user_contacts" : [
{
"friend_list" : "+928885555512",
"user_id" : "1"
},
{
"friend_list" : "+925555648583",
"user_id" : "1"
},
{
"friend_list" : "+925555228243",
"user_id" : "1"
}
]
}
i have created this data through array of dictionaries and its working fine and it is stores in Data
type Variable. As alamofire requires [String: Any]
type of parameter so i have to convert that data into desired format so i tried this:
let my_dict = try JSONSerialization.jsonObject(with: jsonData!, options: []) as! [String: Any]
but when print this my_dict
before call alamofire. it seems that it is not a correct json see below... with something like that: __NSArrayI 0x618000271dc0>
["user_contacts": <__NSArrayI 0x618000271dc0>(
{
"friend_list" = "+928885555512";
"user_id" = "1";
},
{
"friend_list" = "+925555228243";
"user_id" = "1";
},
{
"friend_list" = "+925554787672";
"user_id" = "1";
}
)
]
So how can i make this correct json form? what i am doing wrong?
Updated:
let updated_User_No :[String:Any]=["friend_list": self.new_convert_telephone_no,"user_id": user_no];
user_outer_arrary.append(updated_User_No);
user_inner_array=["user_contacts": user_outer_arrary]
it Should be look like this:
{
"user_contacts" : [
{
"friend_list" : "+928885555512",
"user_id" : "1"
},
{
"friend_list" : "+925555648583",
"user_id" : "1"
}
]
}