When i send an array, im retreiving a wrong JSON in the server:
Client Object:
class Dummy : Mappable {
var test1 = "test1";
var test2 = "test2";
func mapping(map: Map) {
test1 <= map["test1"]
test2 <= map["test2"]
}
required init(){}
}
Client Calling:
let wrongDummies : [Dummy] = [Dummy(), Dummy()];
let wrongDummiesJSONArray = Mapper().toJSONArray(wrongDummies)
let dummies : [String:AnyObject] = [
"right": Mapper().toJSON(Dummy()),
"again_right": ["dummy1" : Mapper().toJSON(Dummy()), "dummy2" : Mapper().toJSON(Dummy())],
"wrong": [Mapper().toJSON(Dummy()), Mapper().toJSON(Dummy())],
"again_wrong": wrongDummiesJSONArray
]
println(dummies)
request(.POST, PROFILE_URL, parameters: dummies)
Client Print (Which seems OK):
[right: {
test1 = test1;
test2 = test2;
}, wrong: (
{
test1 = test1;
test2 = test2;
},
{
test1 = test1;
test2 = test2;
}
), again_right: {
dummy1 = {
test1 = test1;
test2 = test2;
};
dummy2 = {
test1 = test1;
test2 = test2;
};
}, again_wrong: (
{
test1 = test1;
test2 = test2;
},
{
test1 = test1;
test2 = test2;
}
)]
Server implementation (PHP):
ini_set("log_errors", 1);
ini_set("error_log", "$root/php-error.log");
error_log(print_r($_POST, true));
Response server:
Array
(
[again_right] => Array
(
[dummy2] => Array
(
[test2] => test2
[test1] => test1
)
[dummy1] => Array
(
[test2] => test2
[test1] => test1
)
)
[again_wrong] => Array
(
[0] => Array
(
[test2] => test2
)
[1] => Array
(
[test1] => test1
)
[2] => Array
(
[test2] => test2
)
[3] => Array
(
[test1] => test1
)
)
[right] => Array
(
[test2] => test2
[test1] => test1
)
[wrong] => Array
(
[0] => Array
(
[test2] => test2
)
[1] => Array
(
[test1] => test1
)
[2] => Array
(
[test2] => test2
)
[3] => Array
(
[test1] => test1
)
)
)
As you can see the objects inside the array are split by the number of their atributtes, which does not happen with the objects inside the dictionary.