Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post objects array to server #297

Open
andrey-serdyuk opened this issue Jul 5, 2018 · 0 comments
Open

Post objects array to server #297

andrey-serdyuk opened this issue Jul 5, 2018 · 0 comments

Comments

@andrey-serdyuk
Copy link

andrey-serdyuk commented Jul 5, 2018

Hello. I'm trying to post a JSON array of objects to a server. I'm pretty sure that server side works perfectly because I'm interacting with it using android app I have created. I'd be very appreciate if you could help to solve the problem I have with creating the same app on iOS using swift+swithttp.

Here is the method I'm parsing an object to array[string: any].

public func toDictionary() -> [String: Any] {
    var itemDic = [String: Any]()
    
    itemDic["UserId"] = UserId
    itemDic["SelectedItems"] = getSelectedItems()
    
    return itemDic
}

private func getSelectedItems() -> [[String: Any]] {
    var array = [[String: Any]]()
    
    for item in getSelectedItems {
        array.append(item.toDictionary())
    }

    return array
}

When I print toDictionary() result I can see in console the following output:
["UserId": 110021, "SelectedItems": [["AnswerId": 2, "ItemId": 1], ["AnswerId": 2, "ItemId": 4], ["AnswerId": 2, "ItemId": 7]]]

Here is the code how I post the object to the server
HTTP.POST(ServerApi.REPORT, parameters: model.toDictionary()) { response in
//process response
}

The UserId parameter is receiving but the SelectedItems always empty. Can you help me to undestend why this is happen and how can I fix it?

Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant