将url params拆分并转换为字符串值的最佳方法 [英] Best way to split and convert url params into string values
本文介绍了将url params拆分并转换为字符串值的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将iPhone中打开app的自定义网址拆分为值,我的方案如下:
I would like to split a custom url for app opening in iPhone into values, my scheme would be something like:
appname://user=jonsmith&message=blah%20blah
我希望能够在哪里将user和message作为两个NSStrings。关于最佳方法的任何建议?
Where I would like to be able to get "user" and "message" as two NSStrings. Any advice on best approach?
推荐答案
假设你的网址是 NSURL
对象名为 url
:
Assuming your url is in an NSURL
object called url
:
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];
这篇关于将url params拆分并转换为字符串值的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文