【问题标题】:NSURL not getting allocatd with NSStringNSURL 没有被 NSString 分配
【发布时间】:2010-07-08 13:04:39
【问题描述】:

这很奇怪,因为我在程序中的所有其他 NSUrl 都正常工作,但是这个没有被分配 NSString。我正在使用:

urlStr_ = [NSString stringWithFormat:@"http://192.168.10.2/justmeans/trunk/appaddgoodwork?gencode=%@&deviceid=@%@&sessionkey=%@&userid=%@&updatetext=%@&companyid=%d&service_type=%@",securitycode,deviceId,sessionKey,userId,finalTextInTxtVw,companyId,service_type];
urlStr_ = [urlStr_ stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)NSUTF8StringEncoding];

url_ = [[NSURL alloc] initWithString:urlStr_];

NSUrl 没有被分配的可能原因是什么?有人可以帮忙吗?

提前感谢。

附: NSString 不为空。

【问题讨论】:

    标签: iphone nsurl


    【解决方案1】:

    通常这是因为字符串的格式不正确,无法正确编码为 URL。尝试切分字符串以找到有问题的部分。

    【讨论】:

    • 感谢克劳斯的回复。但是“尝试切掉字符串的一些位以找到有问题的部分”是什么意思。我尝试查看字符串是否不包含空格,但发现不是。我真的很困惑。
    【解决方案2】:

    字符串的格式似乎不正确。请参阅%@&deviceid=@%@&sessionkey 部分;不应该是%@&deviceid=%@&sessionkey吗?

    【讨论】:

    • 天哪……感谢您的指出……这对我来说很奇怪……感谢您的帮助……
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    • 2012-04-05
    相关资源
    最近更新 更多