这是我的搜索对象:
package models.helper
import play.api.libs.json.Format
import play.api.libs.json.JsValue
import play.api.libs.json.JsObject
import play.api.libs.json.JsString
case class Search (name: String, `type`:String){
implicit object SearchFormat extends Format[Search] {
def reads(json: JsValue): Search = Search(
(json \ "name").as[String],
(json \ "type").as[String]
)
def writes(s: Search): JsValue = JsObject(Seq(
"name" -> JsString(s.name),
"type" -> JsString(s.`type`)
))
}
}
我想打电话使用WS WebService时,催产素使用这个类:
val search = response.json.as[Search]
但Scala编译器不断抱怨在这条线:
无解串器的Json发现型models.helper.Search。 试图实现一个隐含的读取或格式为这种类型。
任何人可以告诉我,我做错了什么?
- 得到了来自例如https://sites.google.com/site/play20zh/scala-developers/working-with-json
- 此线程讨论了同样的问题,但没有给出解决方案,在什么网站有什么例子? https://groups.google.com/forum/?fromgroups#!topic/play-framework/WTZrmQi5XxY