The documentation for lift-json suggests that I should be able to call 'values' to get my current JObject structure as a vanilla Scala Map. This approach is not working for me, as the return type of 'values' is json.Values rather than a Map as the examples show. What am I doing wrong? Is there an implicit import necessary to accomplish this conversion?
lift-json的文档表明我应该能够调用'values'来将我当前的JObject结构作为一个vanilla Scala Map。这种方法对我不起作用,因为“值”的返回类型是json.Values而不是示例所示的Map。我究竟做错了什么?是否需要隐式导入才能完成此转换?
scala> val json = parse("""{"k1":"v1","k2":"v2"}""")
json: net.liftweb.json.package.JValue = JObject(List(JField(k1,JString(v1)), JField(k2,JString(v2))))
scala> json.values
res4: json.Values = Map((k1,v1), (k2,v2))
scala> res4.get("k1")
<console>:18: error: value get is not a member of json.Values
res4.get("k1")
7
Somehow I missed the duplicate of this in my search: Can I use the Scala lift-json library to parse a JSON into a Map?
不知何故,我在搜索中错过了这个副本:我可以使用Scala lift-json库将JSON解析为Map吗?
Answer is to cast explicitly:
答案是明确施放:
json.asInstanceOf[JObject].values
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2011/04/06/3594f31469e761b78179d7b542b75f6b.html。