【问题标题】:Errors: {"obj.overallCount":[{"msg":["error.path.missing"],"args":[]}]}错误:{"obj.overallCount":[{"msg":["error.path.missing"],"args":[]}]}
【发布时间】:2019-08-27 17:09:02
【问题描述】:

我正在尝试将 json 转换为 Data 类。显示错误

错误: {"obj.overallCount":[{"msg":["error.path.missing"],"args":[]}]}

,我无法找出问题所在。寻求专家的帮助:


case class Count(count:Long)
  case class OverallCount(overallCount:List[Count])

    "JsonTest" should "show result" in {
      Future {


        import play.api.libs.json._

        implicit val count = Json.reads[Count]
        implicit val ovc = Json.reads[OverallCount]

        val jsonString: JsValue = Json.parse(
          """{"countOverall":[{"count":4}]}"""
        )


        val residentFromJson: JsResult[OverallCount] = Json.fromJson[OverallCount](jsonString)


        residentFromJson match {
          case JsSuccess(r: OverallCount, path: JsPath) => Console.println("overallCount: " + r.overallCount)
          case e: JsError => println("Errors: " + JsError.toJson(e).toString())
        }


        succeed
      }
    }

【问题讨论】:

    标签: json scala playframework play-json


    【解决方案1】:
    • 要么替换

      val jsonString: JsValue = Json.parse(
        """{"countOverall":[{"count":4}]}"""
      )
      

      val jsonString: JsValue = Json.parse(
        """{"overallCount":[{"count":4}]}"""
      )
      
    • 或替换

      case class OverallCount(overallCount: List[Count])
      

      case class OverallCount(countOverall: List[Count])
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-28
      • 1970-01-01
      • 2013-01-16
      • 1970-01-01
      • 2016-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多