This is what JSON server is waiting for me

$_POST['json_function'] = '{ "params": { "auth_token": "32342fgh5u6jwjwu25uargat35y", "contacts": [{ "name": "Cheesy", "phone": ["555-478-7672", "555-478-7673"] }, { "name": "Daniel", "phone": ["(555) 564-8583", "####"] }] }, "func": "getContact" 

} ';

problem in making this construct

  "contacts": [{ "name": "Cheesy", "phone": ["555-478-7672", "555-478-7673"] }, { "name": "Daniel", "phone": ["(555) 564-8583", "####"] }] 

There is an array of names and phone arrays

  Contacts.arrContacts Contacts.idPhoneNumber 

This is how I create JSON

  let jsonGetContacts : JSON = [ "func" : "getContact", "params" : [ "auth_token" : "\(userToken)", "contacts" : ?????? ] ] 

How to collect this case, I need help guys

    1 answer 1

    In SwiftyJSON you can simply substitute an array and it will already convert to the desired form. This is if simple. In this case, you must first create an array of objects with the structure

     "name": "Daniel", "phone": ["(555) 564-8583", "####"] 

    and then substitute ?????? at

     "contacts" : ?????? 

    Your 2 arrays must be identical in size and the elements in the array of names match the elements in the array of numbers (and the element is an array of numbers). Can it still be better in the Dictionary array? Then it will turn out something like this:

     var contacts = [[String: AnyObject]]() for i in 0..<Contacts.arrContacts.count { contacts.append(["name": Contacts.arrContacts[i], "phone": Contacts.idPhoneNumber[i]]) } let jsonGetContacts : JSON = [ "func" : "getContact", "params" : [ "auth_token" : "\(userToken)", "contacts" : contacts ] ] 
    • thanks, everything works - Terens777