在我的Scala代码中,我有一个JSON对象,其中包含电子邮件数据。
我需要在每次循环中将 emailJson 添加到 jsonArray 中。
我尝试过:
val messages = inboxEmail.getMessages();
var jsonArray = new JsArray
for(inboxMessage <- messages)
{
...
...
val emailJson = Json.obj("fromAddress" -> fromAddressJsonList, "toAddress" -> toAddressJsonList, "ccAddress" -> ccAddressJsonList, "bccAddress" -> bccAddressJsonList, "subject" -> emailMessage.getSubject().toString(), "message" -> Json.toJson(emailMessageBody))
我需要在每次循环中将 emailJson 添加到 jsonArray 中。
我尝试过:
jsonArray.+:(emailJson)
并且
jsonArray.append(emailJson)
但是获取到了空数组
我应该在这里使用什么来将 jsonObject 添加到 json 数组中