我正在向 AFNetworking 发送针对 Objective-C 的请求。当我 NSLog 参数时,这是我发送的对象:
games = (
{
id = 50;
p = 8;
ts = 0;
tt = ();
tw = 0;
ys = 35150;
yt = {
156424496 = "37.416669";
156609008 = "56.661210";
....
252846816 = "7.075133";
252856944 = "61.329850";
};
yw = 0;
}, ...
这是服务器接收到的。
games = (
{id = 50;},
{p = 8;},
{ts = 0;},
{tw = 0;},
{ys = 35150;},
{
yt = {156424496 = "37.416669";};
},
{
yt = {156609008 = "56.661210";};
},
...
{
yt = {252846816 = "7.075133";};
},
{
yt = {252856944 = "61.329850";};
},
{yw = 0;},
...
就好像它正在获取我的对象的每个属性并用它创建一个新对象。更糟糕的是,它采用数组中的多个对象并将所有对象的所有属性放入数组的相同深度上的单独对象中。
这是我用来发送它的代码:
NSArray *games = [ResourceManager getAllGames];
NSMutableArray *gamesArray = [[NSMutableArray alloc] initWithCapacity:[games count]];
for(Game *g in games)
{
[gamesArray addObject:[g toDictionary]];
}
User *user = [ResourceManager getUser];
NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys:gamesArray, @"games", user.id, @"user_id", nil];
NSLog(@"PARAMS: %@", params); <- this is the first block of code above
[self postPath:API_SYNC_GAMES_URL parameters:params success:^(AFHTTPRequestOperation *operation, id JSON)
{
}
我一直无法弄清楚为什么会发生这种情况,而且我完全没有猜测。如果有人能指出我正确的方向,将不胜感激。
更新
如果我发布一个single object
而不是一个对象数组,它会成功到达服务器。