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

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

我正在尝试将 json 转换为数据 class。它显示错误

Errors: {"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
      }
    }
  • 要么替换

    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])