使用Scala和json4s (也许我错过了一个金鱼库之类的东西)
我正试图向JSON中添加一些字符串列表(或数组),因此最后如下所示:
{"already":"here",..."listToAdd":["a","b",c"]}事实上,我已经在JObject中拥有字符串,而数组字符串中已经有字符串列表。因此,我跟踪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)))使用Scala2.11.4 Json4s 3.2.11 (Jackson)
发布于 2017-04-27 10:30:38
此外,还必须导入一些隐式转换方法:
import org.json4s.JsonDSL._这些将将Scala对象转换为库的Json。
https://stackoverflow.com/questions/43654732
复制相似问题