【发布时间】:2017-04-27 10:09:09
【问题描述】:
使用 Scala 和 json4s(也许我缺少金鱼库什么的)
我正在尝试将一些字符串列表(或数组)添加到 JSON 中,所以最终看起来像:
{"already":"here",..."listToAdd":["a","b",c"]}
事实上,我已经在 JObject 中拥有了字符串,并且在 Array[String] 中拥有了字符串列表(但如果需要,可以将其更改为 List)。所以我关注了docat json4s.org,它指出:
Any seq produces JSON array.
scala> val json = List(1, 2, 3)
scala> compact(render(json))
res0: String = [1,2,3]
Tuple2[String, A] produces field.
scala> val json = ("name" -> "joe")
scala> compact(render(json))
res1: String = {"name":"joe"}
当尝试它时,它会给出:
Error:(15, 28) type mismatch;
found : (String, String)
required: org.json4s.JValue
which expands to) org.json4s.JsonAST.JValue
println(compact(render(idJSON)))
使用 Scala 2.11.4 Json4s 3.2.11(杰克逊)
【问题讨论】: