[英]How do I create JSON objects programmatically in playframework 2.1 scala
http://www.playframework.com/documentation/2.1.x/ScalaJson http://www.playframework.com/documentation/2.1.x/ScalaJson
That document says the idiomatic style of json creation is: 该文档说json创建的惯用风格是:
import play.api.libs.json.Json
Json.obj( "key" -> "value )
However this fails to compile as String -> String is not String -> Json.JsValueWrapper 但是,由于String-> String is not String-> Json.JsValueWrapper,因此无法编译
It appears that play provides the code needed for implicit conversions in play.api.libs.json.{DefaultReads, DefaultWrites} 看来play提供了play.api.libs.json中隐式转换所需的代码。{DefaultReads,DefaultWrites}
How do I get these implicit conversions into scope? 如何将这些隐式转换转换为作用域?
You've misspelt your import statement; 您错了进口声明; it should be
import play.api.libs.json.Json
(it's important to remember Scala is case-sensitive). 它应该
import play.api.libs.json.Json
(记住Scala区分大小写很重要)。 Fixing that, the code works: 解决该问题的代码可以正常工作:
scala> :paste
// Entering paste mode (ctrl-D to finish)
import play.api.libs.json.Json
Json.obj("key" -> "value")
// Exiting paste mode, now interpreting.
import play.api.libs.json.Json
res0: play.api.libs.json.JsObject = {"key":"value"}
scala>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.