八进制转义序列超出范围

时间:2012-02-29 07:16:26

标签: iphone objective-c

我目前正在尝试传递代理,但编译器正在给我一条警告消息 “八进制转义序列超出范围”

  NSURLCredential *credential = [NSURLCredential credentialWithUser:@"asdfg\123456"
                                                             password:@"Zxcvb123!" persistence:NSURLCredentialPersistenceForSession];

我如何删除此警告?

2 个答案:

答案 0 :(得分:1)

如果'\'只是用户凭据的一部分,则需要将其转义:

NSURLCredential *credential = [NSURLCredential credentialWithUser:@"asdfg\\123456"
                                                             password:@"Zxcvb123!" persistence:NSURLCredentialPersistenceForSession];

答案 1 :(得分:1)

问题是用户名中的\(反斜杠)。 \是一个转义字符,当用作\ 121时,它将121解释为八进制数。如果您想在用户名中使用n,请将其写为

NSURLCredential *credential = [NSURLCredential credentialWithUser:@"asdfg\\123456"
                                               password:@"Zxcvb123!"
                                               persistence:NSURLCredentialPersistenceForSession] ;