如何使用 Lift 将 x-www-url 编码的字符串解析为 Map[String, String]?
获取了以下形式的字符串
TOKEN=EC%2d454178600K772032D&TIMESTAMP=2011%2d06%2d29T13%3a10%3a58Z&CORRELATIONID=cbd56e97cad38&ACK=Success&VERSION=64&BUILD=1936884
从 Lift 中,我从 HTTP 请求的响应中
。尽管它可能非常简单,但我找不到将其解析为漂亮的 Map[String, String]
的 Lift 函数。有什么帮助吗?
From Lift, I'm getting a string of the form
TOKEN=EC%2d454178600K772032D&TIMESTAMP=2011%2d06%2d29T13%3a10%3a58Z&CORRELATIONID=cbd56e97cad38&ACK=Success&VERSION=64&BUILD=1936884
from the response of an HTTP request.
Although it's probably ultra-trivial, I can't find the Lift function that parses this into a nice Map[String, String]
. Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
来自 Lift 的 Req.scala:
From Lift's Req.scala:
我还没有看到任何 Lift 的实现。您可以通过以下方式实现此目的:
注意:它假设您有一个格式良好的字符串。在您的代码中,您可能应该检查字符串是否正确。
I haven't seen any Lift's implementation for that. You can achieve this with something like this:
note: it assumes, that you have a well-formed string. In your code you should probably check if the string is ok.
我整理了一个小型 Scala 库来帮助完成此任务: https://github.com/theon/scala-uri
您可以解析 uri 并将参数获取到
Map[String,List[String]]
中,如下所示:它还有一个 DSL,用于使用查询字符串构建 URL:
I put together a small Scala library to help do this: https://github.com/theon/scala-uri
You can parse a uri and get the parameters into a
Map[String,List[String]]
like so:It also has a DSL for building URLs with query strings: