【发布时间】:2017-10-02 12:09:42
【问题描述】:
我正在使用 scala 和 Json4s 在循环中将 JValue 添加到 JArray,这样:
var recordsJArray = JArray
for (record <- recordsList) {
val mrecord= new com.google.gson.Gson().toJson(record.asMap())
val jsonRecord = parse(mrecord)
recordsJArray = recordsJArray.++jsonRecord
}
我已经搜索过 api:https://static.javadoc.io/org.json4s/json4s-core_2.9.1/3.0.0/org/json4s/JsonAST$$JArray.html
我已经尝试使用该方法:
def ++ (other: JValue): JValue
但它不起作用。
error: value ++ is not a member of object org.json4s.JsonAST.JArray
[ERROR] recordsJArray = recordsJArray++jsonRecord
有人可以帮我吗? 有没有办法将 JValue 添加到 JArray 中? 谢谢
【问题讨论】:
-
看起来您使用的版本与您链接的文档不同
-
您好,我使用的是 scala-2.10,json4s 的版本是 maven 存储库中的 3.5.1。我刚刚意识到该链接适用于 2.9.1 javadoc.io/doc/org.json4s/json4s-core_2.10/3.5.1
-
太好了,您现在可以通过查看正确的文档来回答您自己的问题!
-
我在文档中找不到像 ++ 这样的函数,这就是我保留这个问题的原因。我猜这个功能在我的版本中不存在,所以我仍然需要帮助来解决它
-
注意:Json4s 是 vulnerable under DoS/DoW attacks!