【问题标题】:Trying to understand scala code in Activator reactive maps examples in Play2尝试理解 Play2 中 Activator 反应式映射示例中的 scala 代码
【发布时间】:2014-03-25 15:07:21
【问题描述】:

我试图理解Activator reactive maps example 中的以下代码。如果有人能解释代码的( __ \ "event")~ 部分,我将不胜感激。

 object UserPositions {
    implicit def userPositionsFormat: Format[UserPositions] = (
      (__ \ "event").format[String] ~
        (__ \ "positions").format[FeatureCollection[LatLng]]
      ).apply({
      case ("user-positions", positions) => UserPositions(positions)
    }, userPositions => ("user-positions", userPositions.positions))
  }

【问题讨论】:

    标签: scala playframework-2.2 implicit typesafe-activator


    【解决方案1】:

    它将 Json 对象转换为 Scala 对象,反之亦然。 (__ \ "event") 表示 Json 对象的“事件”元素,~ 表示将元素连接成一个元组。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-19
    • 2010-11-16
    相关资源
    最近更新 更多