使用与 net.liftweb.util.JSONParser.parse 结果的模式匹配
我尝试使用 net.liftweb.util.JSONParser 解析 JSON 字符串。它的 parse() 方法返回一个 Box[Any] 值,我想通过这样的模式匹配来处理该值:
JSONParser.parse("{foo: 'xxx', bar: 'yyy'}") match {
case Full(Map) => println("ok")
case x => println(x)
}
我希望这段代码打印“ok”,但它打印出来
Full(Map(foo -> xxx, bar -> yyy))
有人知道我的语句有什么问题吗?
I try to parse a JSON string with the net.liftweb.util.JSONParser. It's parse() method returns a Box[Any] value which I want to process via pattern matching like this:
JSONParser.parse("{foo: 'xxx', bar: 'yyy'}") match {
case Full(Map) => println("ok")
case x => println(x)
}
I'd expect this code to print "ok" but instead it prints
Full(Map(foo -> xxx, bar -> yyy))
Does anyone have an idea what's wrong with my statement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Full(Map)
表示包含单例对象 Map
的Full
。如果你想要Full
里面有一个 Map(对象 Map 不是一个),它应该是Full(m: Map)
(你可以使用_
而不是m
(如果您不需要访问该地图)Full(Map)
means aFull
containing the singletonobject Map
. If you wantFull
with something inside that is a Map (the object Map is not one), it should beFull(m: Map)
(you can use_
instead ofm
if you don't need access to that map)更新:(
我忘记了Map周围的Full()[,]
我不知道你的要求,但是Lift还有另一个比JSONParser更强大的json库,它被称为< a href="https://github.com/lift/framework/tree/master/core/json" rel="nofollow">lift-json
Updated:
(I had forgotten the Full() around the Map[,]
I don't know your requirements, but Lift also has a another json library which is more powerful than JSONParser, it is called lift-json