のためのJSONを作成します。私は[NSObject:AnyObject]
スウィフトは、私はAPIのRESTからの送信のためのJSONを作成する必要があるAPIをREST
var d1 : [NSObject:AnyObject] = ["ownId":"seu_identificador_proprio", "customer":""]
let dd1 = ["currency":"BRL"]
let dd2 = ["shipping":"1000"]
let arr = [d1]
let d = try! NSJSONSerialization.dataWithJSONObject(arr, options: NSJSONWritingOptions.PrettyPrinted)
let s = NSString(data: d, encoding: NSUTF8StringEncoding)! as String
print(s)
で始めてみてください。..
{
"ownId": "seu_identificador_proprio",
"amount": {
"currency": "BRL",
"subtotals": {
"shipping": 1000
}
},
"items": [
{
"product": "Descrição do pedido",
"quantity": 1,
"detail": "Mais info...",
"price": 1000
}
],
"customer": {
"ownId": "seu_identificador_proprio_de_cliente",
"fullname": "Jose Silva",
"email": "[email protected]",
"birthDate": "1988-12-30",
"taxDocument": {
"type": "CPF",
"number": "22222222222"
},
"phone": {
"countryCode": "55",
"areaCode": "11",
"number": "66778899"
},
"shippingAddress": {
"street": "Avenida Faria Lima",
"streetNumber": 2927,
"complement": 8,
"district": "Itaim",
"city": "Sao Paulo",
"state": "SP",
"country": "BRA",
"zipCode": ""
}
}
}
私が作成して混乱しています
を
しかし、私は助けが必要です!
スイフト3を使用していますか? – dirtydanee
いいえ、swift 2.3 @dirtydanee –
あなたの質問は何ですか?あなたが投稿したコードの何が間違っていますか? (BTW、あなたのJSON出力をNSDataから文字列に変換するテスト以外の理由はなく、かなりの印刷形式を使用する理由もありません)RESTfulなサーバーに送信する場合は、pretty形式は使用しないでください。 –