-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
解析URL字符串 #3
Labels
算法&数据结构
算法&数据结构
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
解析字符串
前言
写一个程序
parse
,解析下面的queryString
,返回一个对象分析
首先要先了解
url参数
的规则&
或其他字符进行分割,且以=
分割键值对&
和=
分割时可能没有值=
后面的值可能已经encodeURIComponent
转码,需要解码a[name][second]=careteen&a[company]=sohu&b=y
,需要按层级设置对象a[0]=1&a[1]=2
,此时应该处理返回成数组实现
针对上述分析其规则,解析一个URL需要考虑诸多情况。
具体代码和测试用例实现
下面给出具体实现
辅助函数
测试用例
总结
解析字符串看似简单,实则考察诸多知识点
reduce
去简化流程URL
规则满足各种需求The text was updated successfully, but these errors were encountered: