Let's say I have ....

val obj: MongoDBObject = getDbObj
println(obj)

prints out:

{ "_id" : "1234", "name":"Kevin", "age":"100" }

How can I convert obj to a JsValue?

有帮助吗?

解决方案

This is how you do it for Play 2.1 (documentation)

val dbo = MongoDBObject("id" -> "0001", "name" -> "Kevin", "age" -> "100") 
val json: JsValue = Json.parse(dbo.toString)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top