编码GPS坐标为目标C中的JSON



对不起,如果这是一个非常鲁尼的问题,我只是在网上任何地方都找不到任何答案。在与Facebook Graph API发送之前,我正在尝试将GPS坐标编码为JSON。我认为我正在做正确的事情,但是请继续从API中恢复错误(我肯定这与我如何创建此结构有关(。

这是在目标C中编码GPS坐标的正确方法吗?

NSMutableDictionary *params1 = [NSMutableDictionary dictionaryWithCapacity:3L];
NSString *latStr = [NSString stringWithFormat:@"%f", Coord.latitude];
NSString *lngStr = [NSString stringWithFormat:@"%f", Coord.longitude];
NSString *coordinatesString = [[NSString alloc] initWithFormat:@"%@,%@", latStr, lngStr];
[params1 setObject:dictionaryCoordinates forKey:@"coordinates"];

ps:坐标是一个cllocation coortion2d

这就是我得到的,这对我来说似乎很合适:

coordinates =     {
    latitude = "33.24234";
    longitude = "-120.34224";
};

谢谢!

如果您需要实际数字,则可以做:

NSDictionary *coordinates = @{ @"coordinates": @{ @"latitude": @(Coord.latitude), @"longitude": @(Coord.longitude) } };

@(...)将数字包裹为NSNumber

我没有API的经验,但是我认为坐标是字符串。但是您将它们发送为字符串。

使用NSNumber的实例,而不是NSString. And you should have a view to NSJSONPARSER`。

最新更新