Objective c AFPOST请求中的JSON数据出错

Objective c AFPOST请求中的JSON数据出错,objective-c,json,afnetworking,Objective C,Json,Afnetworking,我正在使用AFNetworking for Objective-C发送请求。当我记录参数时,这就是我要发送的对象: games = ( { id = 50; p = 8; ts = 0; tt = (); tw = 0; ys = 35150; yt = { 156424496 = "37.416669"; 1566090

我正在使用AFNetworking for Objective-C发送请求。当我记录参数时,这就是我要发送的对象:

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)
{
}
NSArray*games=[ResourceManager getAllGames];
NSMutableArray*gamesArray=[[NSMutableArray alloc]initWithCapacity:[游戏计数]];
用于(游戏中的游戏*g)
{
[gamesArray addObject:[g toDictionary];
}
用户*User=[ResourceManager getUser];
NSDictionary*params=[[NSDictionary alloc]initWithObjectsAndKeys:gamesArray、@“games”、user.id、@“user_id”、nil];

NSLog(@“参数:%@”,参数) 我能够通过使用NSDictionary而不是数组来解决这个问题。我拥有的每个对象都有一个唯一的键,因此我将该键用于NSDictionary,如下所示:

NSMutableDictionary *gamesArray = [[NSMutableDictionary alloc] 
                                          initWithCapacity:[games count]];
for(Game *g in games)
{
    [gamesArray setObject:[g toDictionary] 
                   forKey:[NSString stringWithFormat:@"%@", g.id]];
}

这似乎解决了问题。

看看我的答案:


它解决了您的所有问题。

键-值对不应该用逗号分隔吗?您如何将对象序列化为JSON?我正在传递给AFN的是NSDictionary数组request@CraigOtis我更新了问题,以显示我到底是什么doing@brenjt您能否调试
postPath:
方法来确定词典实际上正在被序列化?