gpt4 book ai didi

iphone - 将 url 参数拆分并转换为字符串值的最佳方法

转载 作者:太空狗 更新时间:2023-10-30 03:43:43 26 4
gpt4 key购买 nike

我想将用于在 iPhone 中打开应用程序的自定义 url 拆分为值,我的方案类似于:

appname://user=jonsmith&message=blah%20blah

我希望能够将“用户”和“消息”作为两个 NSString 获取。关于最佳方法的任何建议?

最佳答案

假设您的 url 位于名为 urlNSURL 对象中:

NSMutableDictionary *queryParams = [[NSMutableDictionary alloc] init];
NSArray *components = [[url query] componentsSeparatedByString:@"&"];

for (NSString *component in components) {
NSArray *pair = [component componentsSeparatedByString:@"="];

[queryParams setObject:[[pair objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding: NSMacOSRomanStringEncoding]
forKey:[pair objectAtIndex:0]];
}

...

[queryParams release];

关于iphone - 将 url 参数拆分并转换为字符串值的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2119640/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com