iOS:如何将\ U转换为\ u

时间:2013-10-11 12:05:51

标签: iphone ios objective-c utf-8

  1. 我有NSString,它是unicode编码的。例如عنم12,其内部表示为"\U0639\U0646\U0645\U0661\U0662\U0663"
  2. 我将此字符串发送到远程服务器,该服务器基本上是LAMP服务器。 请注意,我无法访问该服务器
  3. 服务器似乎与\ U有问题,但适用于\ u。
  4. 我尝试了以下一段对我不起作用的代码:

    NSString *resourceparams = [NSString stringWithFormat:@"%@",sender,nil];
    NSLog(@"before replace resourceparams: %@", resourceparams);
    resourceparams = [resourceparams stringByReplacingOccurrencesOfString:@"\\U" withString:@"\\u"];
    NSLog(@"after replace resourceparams: %@", resourceparams);
    
  5. 有什么建议吗?

    编辑:(添加在Post请求正文中发送此数据的方式)

    NSMutableData *postBody = [NSMutableData data];  
    [postBody appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];   
    NSEnumerator * enumerator = [[paramDict allKeys] objectEnumerator];  
    NSString * dataKey = nil;
    while (( dataKey = [enumerator nextObject]) ) {  
        id dataVal = [paramDict objectForKey: dataKey];  
        [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundry] dataUsingEncoding:NSUTF8StringEncoding]];
        if([dataVal isKindOfClass: [NSData class]]) {  
            NSString* contentDisposition = [NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"file.ext\"\r\n", dataKey];  
            [postBody appendData: [contentDisposition dataUsingEncoding:NSUTF8StringEncoding]]; 
            [postBody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; 
            [postBody appendData:dataVal];  
        } else {  
            [postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", dataKey] dataUsingEncoding:NSUTF8StringEncoding]];    
            [postBody appendData:[dataVal dataUsingEncoding:NSUTF8StringEncoding]];  
        }
    

1 个答案:

答案 0 :(得分:0)

您可以尝试使用小写的stringobject。您的功能将如下所示:

NSString *resourceparams = [[NSString stringWithFormat:@"%@",sender,nil] lowerCaseString];

这将使每个nsstring对象不大写。