我正在使用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
}
我搜索过de 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? 谢谢
答案 0 :(得分:0)
SELECT m.major_name,
g.grade,
count(*) as major_grade_count
FROM course c
LEFT JOIN student s USING (st_id)
LEFT JOIN grade g USING (grade_code)
LEFT JOIN major m ON g.major_code = m.major_code -- ADJUST FIELD HERE
GROUP BY m.major_name,
g.grade;
返回<head>
<title>Test</title>
</head>
<body>
<h1>Hi there<span id="username"></span>!</h1>
<script>
let userName = prompt("What is your name?");
document.getElementById('username').innerHTML = userName;
</script>
</body>
,它是++
的超类型。
由于JValue
必须是JArray
,因此Scala编译器正在寻找返回recordsJArray
的{{1}}的实现。既然没有,编译器会报告您所需的函数不是您要在其上调用它的对象的成员。
您可以窃取their implementation of ++
for your input types(JArray和JValue)来代替JsonAST的功能:
JArray