发布一个geoPoint数组作为参数,但来自api响应的数据是否为零?

时间:2017-06-21 04:10:05

标签: ios objective-c json api afnetworking

我需要api发布geoPoint,然后获取数据,这在Postman上运行正常。如图所示, this api works fine on Postman

在我的代码中,我使用以下方式调用api

NSArray *geoPoint = @[@114.33f, @22.44f];

NSDictionary *geoPointDic = @ {@"geoPoint" : geoPoint};
NSDictionary *inData = @{
                         @"action" : @"getNearbyEventList",
                         @"data" : geoPointDic};

NSDictionary *parameters = @{@"data" : inData};

NSLog(@"geoPoint is %@", geoPoint);
NSLog(@"upcoming events parameters %@", parameters);

[_manager POST:GetURL parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  responseObject) {

    NSLog(@"responseObject is %@", responseObject);
    NSLog(@"responseObject - data is %@", responseObject[@"data"]);

    NSArray *eventsArray = responseObject[@"data"];

但输出是

NSLog参数:

events parameters {
    data =     {
        action = getNearbyEventList;
        data =         {
            geoPoint =             (
                "114.33",
                "22.44"
            );
        };
    };
}

the api response looks like

我猜我的参数可能格式错误,所以我尝试了以下方法,但没有人工作

//NSArray *geoPoint = [[NSArray alloc] init];

//NSArray *geoPoint = [[NSArray alloc] initWithObjects:@"114", @"22", nil];

//NSMutableArray *geoPoint = [[NSMutableArray alloc] init];

//[geoPoint addObject:@114];

//[geoPoint addObject:@22];

//NSArray *geoPoint = [[NSArray alloc] initWithObjects:@"114", @"22", nil];

//NSString *geoPoint = @"[114.33,22.44]";

那么,有人可以告诉我如何获取Postman中显示的数据吗?

非常感谢!

1 个答案:

答案 0 :(得分:0)

您可以尝试:

 NSData *dataBody = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];
 NSString *json = [[NSString alloc] initWithData:dataBody encoding:NSUTF8StringEncoding];
 NSLog(@"%@",json);

对象json与发送给服务器的数据相同。