0

Here is the request format that server requires ,

{
 "internal_name": "SDSSD",
 "display_name": "SDSDSDSD",
 "image": "sesse.jpg",
 "notes": "sdsdsdsdsdsdsdsd",
 "short_description": "ssdsdsd",
 "long_description": "sdsdsdsd",
 "ean_code": "3434343434",
 "status": "not_verified",
 "state": "active",
 "quantity": 1,
 "brand": {
   “name”: “My Brand”
 },
 "categories": [
   {
     “id”: “My Category”
   }
 ]
}

In here , as you can see , it requires , categories as an array , so my question is how can i create an array . using swift . here is my swift code

let parameters :[String:AnyObject] = [
            "internal_name":product.displayName,
            "display_name":product.displayName,
            "language":Constant.Language.LAN_ENGLISH,
            "notes":product.initialName,
            "image": product.photo,
            "short_description":product.longDescription,
            "long_description":product.longDescription,
            "ean_code":product.eanCode,
            "status":product.status,
            "state":Constant.Status.STATUS_ACTIVE,
            "categories": [
                "id":product.categoryObject.id
            ],
            "quantity":1,

        ]

this doesnt accept from the server since its not an array , what am i missing here

1 Answer 1

1

Try below code :

let parameters :Parameters = [
        "internal_name":product.displayName,
        "display_name":product.displayName,
        "language":Constant.Language.LAN_ENGLISH,
        "notes":product.initialName,
        "image": product.photo,
        "short_description":product.longDescription,
        "long_description":product.longDescription,
        "ean_code":product.eanCode,
        "status":product.status,
        "state":Constant.Status.STATUS_ACTIVE,
        "brand" : ["name" : "My Brand"],
        "categories": [
            ["id":product.categoryObject.id]
        ],
        "quantity":1,
        ]
Sign up to request clarification or add additional context in comments.

4 Comments

seems its not the correct way to send, server doesnt acceppts it
Why? I have already pass this json to server. And its working fine. Have you add this code?
yes the issue is in here it seems "categories": [ ["id":product.categoryObject.id] ],
Yes I think that's is bug in Alamofire to reinstall app. Thanks :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.