POST请求,JAVA后台,个别接口传参要求传JSON数据,并且
不带key
的那种……
如果你的网络框架也是AFNetworking,那么请你找到AFURLRequestSerialization这个类,在这个类的.m文件中,有一个叫做URLEncodedStringValue的方法。
源码
- (NSString *)URLEncodedStringValue {
if (!self.value || [self.value isEqual:[NSNull null]]) {
return AFPercentEscapedStringFromString([self.field description]);
} else {
return [NSString stringWithFormat:@"%@=%@", AFPercentEscapedStringFromString([self.field description]), AFPercentEscapedStringFromString([self.value description])];
}
}
改成
- (NSString *)URLEncodedStringValue {
if (!self.value || [self.value isEqual:[NSNull null]]) {
return AFPercentEscapedStringFromString([self.field description]);
}else if(!self.field || [self.field isEqual:[NSNull null]]){
return [NSString stringWithFormat:@"%@",self.value];
}else {
return [NSString stringWithFormat:@"%@=%@", AFPercentEscapedStringFromString([self.field description]), AFPercentEscapedStringFromString([self.value description])];
}
}
网友评论