post json编码参数swift

时间:2016-03-22 10:00:04

标签: ios objective-c json swift swift2

您能否建议我如何在swift或Objective c中传递以下参数

         let parameters = ["Access_Key":"0699DADD8A2B5FC2E8FF6FF5DDFE03EEDB3ED2132B29EA4F28","Packages":["Length":self.Length,"Type":"","Kg":self.Weight,"Height":self.Height,"Width":self.Width,"Name":self.SkuName],
                      "issignaturerequired":"true",
                      "Outputs":["LABEL_PNG_100X175"],
                      "DeliveryReference":"86882",
                      "Destination":["ContactPerson":self.CustomerFirstname,"Address":["PostCode":self.PostalCode,"StreetAddress":self.Address1,"Suburb":self.City,"BuildingName":"","City":self.City,"CountryCode":"AU"],"PhoneNumber":"","Email":self.CustomerEmail,"Name":self.CustomerFirstname],
                      "PrintToPrinter":"true",
                      "SendTrackingEmail":"",
        "Commodities":["UnitKg":"1.0000","Currency":"NZD","Country":"NZ","Units":"1","Description":"Drums Drum Accessories Drum Bags","UnitValue":"44.0"],
        "DeliveryInstructions":"None"
                     ]
    Alamofire.request(.POST, "http://api.omniparcel.com/labels/printcheapestcourier",parameters: parameters, encoding: .JSON)
        .responseJSON { response in
            print(response)
    }
}

我是iOS的新手

1 个答案:

答案 0 :(得分:1)

我建议您在Swift中使用EVReflection作为JSON对象。

只需为您的JSON对象创建一个对象,然后将 myJsonObject.toDictionary()作为参数传递给Alamofire。