2
如何在Play中構建Reads! 2.1.1它讀取這個JSON?下面的示例和代碼會引發異常。我可以在Play中運行它!控制檯,但如果我啓動服務器並使用curl,則會出現錯誤。如何使用讀取來分析JSON並使用整數列表
{
"title": "title",
"description": "description",
"categories": [1,3],
"sections": [2]
}
按照播放指南!網站使我創建了這個「解析器」,但它引發了一個異常。
implicit val guideReads: Reads[GuideInstance.Update] = (
(__ \ "title").readNullable[String] ~
(__ \ "description").readNullable[String] ~
(__ \ "categories").readNullable(
Reads.list[Int]
) ~
(__ \ "sections").readNullable(
Reads.list[Int]
)
)(GuideInstance.Update)
異常
java.lang.NullPointerException: null
at play.api.libs.json.Json$.fromJson(Json.scala:90) ~[play_2.10.jar:2.1.1]
at play.api.libs.json.DefaultReads$$anon$2$$anonfun$10.apply(Reads.scala:453) ~[play_2.10.jar:2.1.1]
.......
at play.api.libs.json.JsValue$class.validate(JsValue.scala:73) ~[play_2.10.jar:2.1.1]
at play.api.libs.json.JsObject.validate(JsValue.scala:159) ~[play_2.10.jar:2.1.1]
at controllers.mtadmin.GuidesController$$anonfun$update$1.apply(GuidesController.scala:114) ~[na:na]
at controllers.mtadmin.GuidesController$$anonfun$update$1.apply(GuidesController.scala:114) ~[na:na]