2017-03-03 56 views
1

這裏是我要發送作爲參數我的鍵值對的結構。如何使一個JSON對象通過POST發送API它迅速3?

KEY是rest_order

值是花括號內

rest_order 
{ 

    "address":"liberty", 
    "order_price":"1100", 
    "fname":"rara", 
    "lname":"bbaba", 
    "phone":"1100", 
    "order_prod":[ 
     { 
      "prod_id":"10", 
      "units":"10" 
     }, 
     { 
      "prod_id":"2", 
      "units":"1" 
     } 
    ] 
} 

回答

0

類order_prod {

var units : String; 
var prod_id : String; 

func toAnyObject() -> Any{ 
    return [ 
     "units": self.units, 
     "prod_id": prod_id 
    ] 
} 

}

這將是類返回你所需要的字典在夫特3

類模型 {

var order_prod = [order_prod]() 
var address : String 
var order_price : String 
var fname: String 
var lname : String 
var phone : String 

func toAnyObject() -> Any{ 


    var arrr = Array<Any>() 
    for i in self.order_prod 
    { 
     arrr.append(i.toAnyObject()) 
    } 
    return [ 
     "order_prod": self.arrr, 
     "address": self.address, 
     "order_price" : self.order_price, 
     "fname": self.fname, 
     "lname": self.lname, 
     "phone": self.phone 
    ] 
} 

}