我需要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"
);
};
};
}
我猜我的参数可能格式错误,所以我尝试了以下方法,但没有人工作
//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
中显示的数据吗?
非常感谢!
答案 0 :(得分:0)
您可以尝试:
NSData *dataBody = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];
NSString *json = [[NSString alloc] initWithData:dataBody encoding:NSUTF8StringEncoding];
NSLog(@"%@",json);
对象json与发送给服务器的数据相同。