将查询字符串按“但是,有些属性具有此“”。在值中
我试图通过“&”来拆分查询,但是一些属性也具有此“&”在值中,我可以知道如何将其分开吗?例如:
const query = "attr1=value1&attr2=va & lu&e2&attr3=value3"
我可以知道如何将查询分为数组而不将“ VA& lu& e2”分开:
["attr1=value1", "attr2=va &%lu&e2", "attr3=value3"]
谢谢!
I try to split an query by "&", but some attribute also has this "&" in the value, may I know how to split it? For example:
const query = "attr1=value1&attr2=va & lu&e2&attr3=value3"
May I know how to split the query into an array without splitting the "va & lu&e2":
["attr1=value1", "attr2=va &%lu&e2", "attr3=value3"]
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果要在查询上使用这些参数,
您应该使用Encodeuricomponent(),该eNCODEROMOMPONTINT()可以逃脱字符串,以便在查询中用作值。
这将导致以下字符串:
因此每个'&'被编码为“%26”
以拆分它,您现在可以依靠'&'符号:
虽然,我将对每个查询参数值使用Encodeuricomponent()。除非我确切地知道我使用哪个值,并且不需要逃脱。
if you want to use these parameters on a query,
you should use encodeURIComponent() which will escape the string so it can be used as a value in a query.
This will result in the following string:
So every '&' is encoded as '%26'
To split it you can now rely on the '&' sign:
Although, I would use the encodeURIComponent() for every query parameter value. unless I know exactly which value I use and that it doesn't need escaping.
您可以标记&当您将其用作值时,有所不同:类似&例如,然后创建自己的函数以进行分裂。
像:
代码可能不起作用,但希望这可以澄清一些东西
you could mark & differently when you are using it as a value: something like & for example and then create your own function for splitting.
like:
the code probably does not work, but hopes this can clarify something