-1
我需要发送json字典作为参数,我正在使用网络连接。在使用下面的代码我得到一个例外:iOS中的JSON错误
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", nil];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
NSDictionary *params = @{@"email":txt_email.text,@"password":txt_password.text,@"platform":@"iphone"};
NSLog(@"params:%@",params);
SBJsonWriter *jsonWriter=[[SBJsonWriter alloc]init];
NSString *paramsDicJSONN = [jsonWriter stringWithObject:params];
NSString *str_url=[NSString stringWithFormat:@"%@do_signup",BaseURLlogin];
[manager POST:str_url parameters:paramsDicJSONN success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"offerJSON: %@", responseObject);
例外:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSJSONSerialization dataWithJSONObject:options:error:]: Invalid top-level type in JSON write'
服务器将接受json格式,如果我将它作为params传递,我将不会得到response.Any方法传递json dic作为参数 – user3388273 2014-10-27 12:39:45
如果要发布JSON字符串,则需要使用其他方法,此方法需要一个'NSDictionary'。 – zaph 2014-10-27 12:45:12