Alamofire使用JSON加入参数

时间:2015-07-23 18:55:08

标签: ios json swift alamofire

我将参数发送到我的服务器,如下所示:

request(.POST, PROFILE_URL, parameters: customer, encoding: ParameterEncoding.JSON).responseJSON(options: NSJSONReadingOptions.AllowFragments) { (request, response, json, error) -> Void in

客户是:

(lldb) po customer
["addresses": (
{
address = "c/ Juan Ricardo de Dios, Madrid";
addressName = "Mi primo Richard";
id = 1;
idDeliveryArea = 1;
nonSelectableArea = Elda;
phone = 96543234;
},
{
address = "c/ Fernando Soria";
addressName = "Hermano Juan";
id = 2;
idDeliveryArea = 2;
nonSelectableArea = Petrer;
phone = 96542134;
}
), "idsFavorites": (
1,
2,
3
), "id": 1, "lastName": Sanchez Validísimo, "currentSelectedAddress": {
address = "c/ Fernando Soria";
addressName = "Hermano Juan";
id = 2;
idDeliveryArea = 2;
nonSelectableArea = Petrer;
phone = 96542134;
}, "birthdate": 616940595, "email": valid@valid.com, "name": Valido]

(lldb) 

在服务器中我得到一个空数组: [23-Jul-2015 18:01:47 Europe / Berlin] Array     (     ) 如果我改变enconding到ParameterEncoding.URL我得到地址dictorionay像一个数组,真的很奇怪:

addresses] => Array
(
[0] => Array
(
[nonSelectableArea] => Elda
)

        [1] => Array
            (
                [address] => c/ Juan Ricardo de Dios, Madrid
            )

        [2] => Array
            (
                [idDeliveryArea] => 1
            )

        [3] => Array
            (
                [id] => 1
            )

        [4] => Array
            (
                [addressName] => Mi primo Richard
            )

        [5] => Array
            (
                [phone] => 96543234
            )

        [6] => Array
            (
                [nonSelectableArea] => Petrer
            )

        [7] => Array
            (
                [address] => c/ Fernando Soria
            )

        [8] => Array
            (
                [idDeliveryArea] => 2
            )

        [9] => Array
            (
                [id] => 2
            )

        [10] => Array
            (
                [addressName] => Hermano Juan
            )

        [11] => Array
            (
                [phone] => 96542134
            )

    )

[birthdate] => 616940595
[currentSelectedAddress] => Array
    (
        [nonSelectableArea] => Petrer
        [address] => c/ Fernando Soria
        [idDeliveryArea] => 2
        [id] => 2
        [addressName] => Hermano Juan
        [phone] => 96542134
    )

[email] => valid@valid.com
[id] => 1
[idsFavorites] => Array
    (
        [0] => 1
        [1] => 2
        [2] => 3
    )

[lastName] => Sanchez Validísimo
[name] => Valido

服务器端详细信息:

<?php
ini_set('display_errors', true);
$root = realpath($_SERVER["DOCUMENT_ROOT"])."/webservice/test";

$customer = $_POST['customer'];
$idCustomer = $customer['id'];

ini_set("log_errors", 1);
ini_set("error_log", "$root/php-error.log");
error_log(print_r($_POST,true));

0 个答案:

没有答案