我正在使用 play 2.1.1 并且在遍历数组时遇到问题。我在某处读过,您可以为 List[Object] 创建读取,但每次我尝试这样做时,我都会收到一条错误"No unapply function found"
消息
implicit val userListReads: Reads[List[FBUser]] = Json.reads[List[FBUser]]". The issue is " = Json.reads[List[FBUser]]
我不知道还能尝试什么。任何帮助将不胜感激。
def linkUsers() = Action { implicit request =>
val json = Json.parse("{\"data\": [{\"name\": \"Me Lazyan\",\"id\": \"1182\"},{\"name\": \"Chales Dselle\",\"id\": \"10115\"},{\"name\": \"Be My\",\"id\": \"10275\"},{\"name\": \"De Rwani\", \"id\": \"11189\"},{\"name\": \"Phoe Johon\", \"id\": \"11372\"}]}")
val peoples = json.validate[List[FBUser]].get
peoples.foreach(println)
Ok(json).withHeaders(CONTENT_TYPE -> "text/json")
}
case class FBUser(
name: String,
id: String
)
object FBUser {
/** Uses a Scala Macro to define the Reads function */
implicit val userReads: Reads[FBUser] = Json.reads[FBUser]
implicit val userListReads: Reads[List[FBUser]] = Json.reads[List[FBUser]]
}