1

当我在组合器http://www.playframework.com/documentation/2.2.x/ScalaJsonCombinators的文档中尝试第一个示例时,它会在 repl 中引发错误,并且在播放应用程序中找不到 scala 文件的值(尝试过使用 play 2.2.0 和 play 2.1.1) - 从 repl 追溯:

Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :paste
// Entering paste mode (ctrl-D to finish)

import play.api.libs.json._
import play.api.libs.functional.syntax._

val customReads: Reads[(String, Float, List[String])] = 
  (JsPath \ "key1").read[String](email keepAnd minLength(5)) and 
  (JsPath \ "key2").read[Float](min(45)) and
  (JsPath \ "key3").read[List[String]] 
  tupled


// Exiting paste mode, now interpreting.

<console>:16: error: not found: value tupled
        tupled
        ^
<console>:11: error: not found: value email
        (JsPath \ "key1").read[String](email keepAnd minLength(5)) and 
                       ^

scala> 

那么如何解决呢?

谢谢

4

1 回答 1

1

两个问题。首先,您还需要一个导入:

import play.api.libs.json.Reads._

其次,文档可能是在“minLength”和“min”等函数被通用化之前编写的,以处理的不仅仅是字符串和浮点数。所以你必须为那些指定类型:

val customReads: Reads[(String, Float, List[String])] =
    (JsPath \ "key1").read[String](email keepAnd minLength[String](5)) and
    (JsPath \ "key2").read[Float](min[Float](45)) and
    (JsPath \ "key3").read[List[String]]
    tupled

这是我读到的讨论,我发现关于此的信息:

游戏框架谷歌小组讨论

于 2013-10-25T04:58:24.370 回答