在Scala中,我想解析使用Travis CI REST API检索的JSON响应。为此,我决定使用play-json库。除此之外,根据REST API'架构',我定义了以下案例类:
case class Build(id : Int,
repository_id : Int,
commit_id : Int,
number : String,
event_type : String,
pull_request : Boolean,
pull_request_title : String,
pull_request_number : String,
state : String,
started_at : String,
finished_at : String,
duration : Int,
job_ids : List[Int]) extends Serializable{
}
case class Builds(builds : List[Build])
实施本身应该是不言自明的,但如果需要进一步说明,我会更新问题。
除此之外,我还为play-json库定义了以下Read:
implicit val buildReads : Reads[Build] = (
(JsPath \ "id").read[Int] and
(JsPath \ "repository_id").read[Int] and
(JsPath \ "commit_id").read[Int] and
(JsPath \ "number").read[String] and
(JsPath \ "event_type").read[String] and
(JsPath \ "pull_request").read[Boolean] and
(JsPath \ "pull_request_title").read[String] and
(JsPath \ "pull_request_number").read[String] and
(JsPath \ "state").read[String] and
(JsPath \ "started_at").read[String] and
(JsPath \ "finished_at").read[String] and
(JsPath \ "duration").read[Int] and
(JsPath \ "job_ids").read[List[Int]]
)(Build.apply _)
implicit val buildsReads : Reads[Builds] = (__ \ "builds").read[List[Build]].map(Builds(_))
代码确实编译,架构即案例类确实对REST API响应进行了确认,但是,在验证响应时,我收到以下错误:
JsError(List((/ builds(0)/ pull_request_title,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(0)/ pull_request_number,List(ValidationError(List) (error.expected.jsstring),WrappedArray()))),(/ builds(1)/ pull_request_title,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(1) / pull_request_number,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(2)/ pull_request_title,List(ValidationError(List(error.expected.jsstring),WrappedArray())) ),(/ builds(2)/ pull_request_number,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ buildd(3)/pull_request_title,List(ValidationError(List(error.expected。)。 jsstring),WrappedArray()))),(/ builds(3)/ pull_request_number,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(4)/ pull_request_title,List( ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ buildd(4)/ pull_request_number,List(ValididationError(List(error).expecte d.jsstring),WrappedArray()))),(/ builds(5)/ pull_request_title,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(5)/ pull_request_number, List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(6)/ pull_request_number,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),( / builds(7)/ pull_request_title,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ buildd(7)/pull_request_number,List(ValididationError(List(error.expected.jsstring)), WrappedArray()))),(/ builds(8)/ pull_request_title,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(8)/ pull_request_number,List(ValidationError(List) (error.expected.jsstring),WrappedArray()))),(/ builds(9)/ pull_request_title,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(9) / pull_request_number,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(10)/ pull_request_title,List(ValidationError(Li) st(error.expected.jsstring),WrappedArray()))),(/ builds(10)/ pull_request_number,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(11) )/ pull_request_number,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(12)/ pull_request_title,List(ValidationError(List(error.expected.jsstring),WrappedArray()) )),(/ builds(12)/ pull_request_number,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ buildd(13)/pull_request_title,List(ValidationError(List(error).expected .jsstring),WrappedArray()))),(/ builds(13)/ pull_request_number,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(14)/ pull_request_title,List (ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(14)/ pull_request_number,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(15)/ pull_request_title,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(15)/ pull_request_numb呃,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(16)/ pull_request_number,List(ValidationError(List(error.expected.jsstring),WrappedArray()))) ,(/ builds(17)/ pull_request_number,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ buildd(18)/ dep_request_title,List(ValidationError(List(error.expected.jsstring) ),WrappedArray()))),(/ builds(18)/ pull_request_number,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(19)/ pull_request_title,List(ValidationError) (List(error.expected.jsstring),WrappedArray()))),(/ builds(19)/ pull_request_number,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds( 20)/ pull_request_title,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(20)/ pull_request_number,List(ValidationError(List(error.expected.jsstring),WrappedArray() ))),(/ builds(21)/ pull_request_number,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ b uilds(22)/ pull_request_title,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ buildd(22)/ pull_request_number,List(ValididationError(list(error.expected.jsstring),WrappedArray ()))),(/ builds(23)/ pull_request_title,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(23)/ pull_request_number,List(ValidationError(List( error.expected.jsstring),WrappedArray()))),(/ builds(24)/ pull_request_title,List(ValidationError(List(error.expected.jsstring),WrappedArray()))),(/ builds(24)/ pull_request_number,列表(ValidationError(列表(error.expected.jsstring),WrappedArray())))))
问题可能是什么的任何线索?提前谢谢!