NSDictionary * elemDict = @{@"deviceType":@"2",//设备类型:2:iOS
@"token":[User_Def objectForKey:USER_TOKEN]?[User_Def objectForKey:USER_TOKEN]:@"",//token
@"title":@"测试?",//主题
@"content":@"测试333..........#",//内容
@"startDate":@"2017-09-19 12:56",//开始日期
@"endDate":@"2017-09-29 13:56",//结束日期
@"location":@"SaaS",//地址
};
NSString * elementStr = [elemDict yy_modelToJSONString]; //json相连
NSString * base64ElementStr = [elementStr GTM64Encode];
NSString * urlStr = [NSString stringWithFormat:@"%@%@%@%@",Url_Header,CreateActivityGroupUrl,DataCodeUrl,base64ElementStr];
urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters: [NSCharacterSet characterSetWithCharactersInString:urlStr]];
[NetRequest_Shared POSTChineseUrl:urlStr parameters:nil success:^(id _Nullable responseObject) {
NSLog(@"%@",responseObject);
if ([responseObject[@"Code"] integerValue] == 0) {
[SVProgressHUD showSuccessWithStatus:@"创建活动成功!"];
[SVProgressHUD setAnimationDelay:1.5f];
dispatch_async(dispatch_get_main_queue(), ^{
[self.navigationController popViewControllerAnimated:YES];
});
}
if ([responseObject[@"Code"] integerValue] == 100) {
//只显示文字
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeText;
hud.label.text = responseObject[@"CodeMsg"];
hud.margin = 10.f;
hud.offset = CGPointMake(0, 0.f);
hud.removeFromSuperViewOnHide = YES;
[hud hideAnimated:YES afterDelay:1.5f];
[SVProgressHUD dismiss];
}
} failure:^(NSError * _Nonnull error) {
NSLog(@"%@",error);
NSLog (@"operation: %@",[error localizedDescription] );
//只显示文字
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeText;
hud.label.text = [error localizedDescription];
hud.margin = 10.f;
hud.offset = CGPointMake(0, 0.f);
hud.removeFromSuperViewOnHide = YES;
[hud hideAnimated:YES afterDelay:1.5f];
[SVProgressHUD dismiss];
} ];
数据字典——json字符串——base64加密——拼接为URL Post请求
老报这种错{
Code = 100;
CodeMsg = "Unterminated string at character 208 of {\"location\":\"SaaS\",\"content\":\"\U6d4bT\Ufffd\Ufffd\U0338\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\U0454\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\U0734\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\U0608\Ufffd\Ufffd\Ufffd\U0445\Ufffd\Ufffd\Ufffd\U0454\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\U0734\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\U0608\Ufffd\Ufffd\Ufffd\Ufffd\U0665\Ufffd\UfffdQ\Ufffd\Ufffd\Ufffd\Ufffd\Ufffd\U0208\Ufffd\Ufffd\U0465\U0471\Ufffd\Ufffd\U82da\UfffdW\Ufffd\Ufffd|\Ufffd\Ufffd\Ufffd\U047d\Ufffd\Ufffd\Ufffd\Ufffd\U8255\Ufffd)\Ufffd\Ufffd!\t]ia)\Ufffdi\Ufffd\Ufffd\UfffdeaI\Ufffd\Ufffd\Ufffd\U0465=\Ufffd%\Ufffd9\Ufffdi\Ufffd=Q\Ufffd\Ufffdi\Ufffd9Q\UfffdeQ\Ufffd\UfffdeQT\Ufffd9Q4\Ufffdd\Ufffd\Ufffde\Ufffde\Ufffd5\Ufffd\Ufffd5\Ufffd%\Ufffd%\UfffdY\Ufffdia))i $\Ufffd%\UfffdD\Ufffde\UfffdY\Ufffd5Y\Ufffdi\UfffdT\UfffdeQD\Ufffd9\Ufffd\Ufffde\Ufffdi\Ufffd5\Ufffd\Ufffdi]i\Ufffd9\Ufffd\Ufffd\Ufffd=%\Ufffd%\Ufffd\Ufffd\Ufffd";
}
解决了
NSString * base64ElementStr = [elementStr base64Code];
后面加:
base64ElementStr = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(CFStringRef)base64ElementStr,NULL,CFSTR("!*'();:@&=+$,/?%#[]"),kCFStringEncodingUTF8));//不规则的base64字符修改成规则
用的三方的base64加密,没处理不规则的字符 。。。