我有一个可以工作的函数:
def convertUsersToJsonOrig(lusers: Seq[User]): JsValue = {
Json.toJson(
lusers.map { u => Map("id" -> u.id,
"firstName" -> u.firstName,
"lastName" -> u.lastName,
"mobile" -> u.mobile,
"email" -> u.email,
"username" -> u.username,
"password" -> u.password)}
)}
但是,我想添加一个字段,如下所示:
def convertUsersToJsonOrig(lusers: Seq[User]): JsValue = {
Json.toJson(
lusers.map { u => Map("id" -> u.id,
"firstName" -> u.firstName,
"lastName" -> u.lastName,
"mobile" -> u.mobile,
"email" -> u.email,
"username" -> u.username,
"password" -> u.password,
"rowNum" -> 0
)}
)
}但这给了我一个错误:
No Json serializer found for type Seq[scala.collection.immutable.Map[String,Any]]. Try to implement an implicit Writes or Format for this type.rowNum不是用户的字段。
这样的事情能做吗?谢谢!
发布于 2017-04-21 00:59:21
好吧,我不能在Scala中添加这个字段。但是,我可以在ES6中使用:
$.extend(true, {}, {'rowNumber':i}, json_data [i])其中json_data包含包含来自服务器的所有对象的数组。
https://stackoverflow.com/questions/43524287
复制相似问题