我正在尝试将json响应提取到我的项目中的case类,但是出现错误提示:
Error Message is : No usable value for httpCode Did not find value which can be converted into int
如果我调用API并将其提取出来,就会发生这种情况,但是当我将json
响应显式设置为json
解析器时,当我提取它们时,它们运行良好。
我的json
答复是:
{
"httpCode": 200,"statusCode": "S_QUERY_1000","description": "Operation successful","data": [
{
"id": "5de0e1b3b2613f221986ff79","serial": "36c51161f820c2bc5c5bb83ee08881bb","type": "DOOR_OPEN","deviceLabel": "Door Sensor 2","locationLabel": "Support","notificationIds": [
{
"type": "FIREBASE","id": "1575018930989-6611da04-e2fa-4402-b16a-09c8ad8be2d5"
},{
"type": "IVR","id": "48eb911aa838b54a96e6402947c48db4"
}
],"acknowledgedBy": null,"acknowledgmentType": null,"acknowledgedDeviceLabel": null,"reason": null,"description": null,"processor": "alt_p_01","initiatedDateTime": "2019-11-29T09:15:31.027Z","acknowledgedDateTime": null,"sirenOnTime": null,"sirenOffTime": "2020-01-21T12:16:21.445+08:00","updatedDateTime": "2020-01-21T12:16:21.923+08:00","status": "PROCESSING"
},{
"id": "5de0dcf7b2613f221986ff78","type": "MOTION_DETECTED","deviceLabel": "Tri-Sensor 1","locationLabel": "Lunch Room","id": "1575017719760-53662549-d482-4759-94d7-5ec7fdb29309"
},"id": "a76d9424328efc7084add0cc46bcaa28"
}
],"initiatedDateTime": "2019-11-29T08:55:19.807Z","sirenOffTime": null,"updatedDateTime": "2019-11-29T08:58:23.775Z",{
"id": "5de0dc4bb2613f221986ff77","deviceLabel": "Door Sensor 3","locationLabel": "Home","id": "1575017547742-d018d984-ed70-4fda-9458-8d84288fca00"
},"id": "8896fee125ed12d9cfbc3de07d3dbc6a"
}
],"initiatedDateTime": "2019-11-29T08:52:27.803Z","updatedDateTime": "2019-11-29T08:55:29.705Z",{
"id": "5de0dc36b2613f221986ff76","id": "1575017526822-87d03515-21ca-45d4-b3f9-f12988a4a5b5"
},"id": "d10ab1e5cc802e6367989b9e29840e32"
}
],"initiatedDateTime": "2019-11-29T08:52:06.857Z","updatedDateTime": "2019-11-29T08:55:08.682Z",{
"id": "5de0dbdab2613f221986ff75","id": "1575017434604-19461ead-3b17-4648-bc70-d01ec8c113a5"
},"id": "289d0495bcc937ab30000a8c0c2253f3"
}
],"initiatedDateTime": "2019-11-29T08:50:34.635Z","updatedDateTime": "2019-11-29T08:53:35.641Z",{
"id": "5de0db0cb2613f221986ff74","deviceLabel": "Tri-Sensor 5","locationLabel": "Lobby","id": "1575017228218-85607147-9414-40d7-b7dc-e4e7acd717db"
},"id": "6cef5f5fde5f3209d845390db04bc402"
}
],"initiatedDateTime": "2019-11-29T08:47:08.284Z","updatedDateTime": "2019-11-29T08:50:11.561Z",{
"id": "5de0db09b2613f221986ff73","id": "1575017225719-cd828cfb-2570-4e9d-a60e-e0714a14830b"
},"id": "9c30bf0ea2ed111788f72fdef8b3e295"
}
],"initiatedDateTime": "2019-11-29T08:47:05.755Z","updatedDateTime": "2019-11-29T08:50:08.541Z",{
"id": "5de0da9bb2613f221986ff72","id": "1575017115516-15600a8b-f387-46c7-8aa8-6c2575c0ab42"
},"id": "41e45e6f791bee847e73ff083fce43c5"
}
],"initiatedDateTime": "2019-11-29T08:45:15.547Z","updatedDateTime": "2019-11-29T08:48:17.485Z",{
"id": "5de0da5ab2613f221986ff71","id": "1575017050570-97586921-28d7-447d-b237-53e62e2f9c2c"
},"id": "1aa425cb42031e9f2eb028cb8ec16aed"
}
],"initiatedDateTime": "2019-11-29T08:44:10.655Z","updatedDateTime": "2019-11-29T08:47:14.454Z",{
"id": "5de0da4bb2613f221986ff70","id": "1575017035919-35b2b84f-f11d-4bd3-9ce1-0a094cb57c8c"
},"id": "89c98b5781bd3e8df415230fc9ce19c5"
}
],"initiatedDateTime": "2019-11-29T08:43:55.956Z","updatedDateTime": "2019-11-29T08:46:59.435Z","status": "PROCESSING"
}
],"meta": {
"currentPage": 1,"nextPage": 2,"numOfPages": 244,"previousPage": 0
}
}
我处理此case classes
响应的json
是:
case class Alerts(httpCode: String,statusCode: String,description: String,data: List[Data])
case class Data(id: String,serial: String,`type`: String,deviceLabel: String,locationLabel: String,notificationIds: List[NotificationIds],acknowledgedBy: String,acknowledgmentType: String,acknowledgedDeviceLabel: String,reason: String,processor: String,initiatedDateTime: String,acknowledgedDateTime: String,sirenOnTime: String,sirenOffTime: String,updatedDateTime: String,status: String)
case class NotificationIds(`type`: String,id: String)
我提取的方式是:
implicit val format = DefaultFormats
//this api cal returns the response I stated above
val url = ServerConfigs.thingHttpHost+ServerConfigs.thingPathForactiveAlerts+serial
val jsonResponse = scala.io.Source.fromURL(url).mkString
val resData = jsonResponse.extract[Alerts]
请协助。