获取 Json 到模型对象
Getting Json to a model object
我需要 Json 我的模型,但我有问题(我是初学者)。
我的模型
https://gist.github.com/anonymous/1c2e88cb83cbeace6f34
我需要让 json 进入我的模型
我需要 json-> 进行模型转换
我使用网络服务获取 json
以及如何为我的模型实现作业对象列表
控制器
https://gist.github.com/anonymous/c526483b29be0b198bca
我需要对象来编辑一些细节,我想重新转换为 Json
我的看法是这样的
我有新想法
谢谢...
看起来你几乎拥有你需要的一切。要将 JSON 中的 builds
转换为 Build
的列表,您可以这样做:
val js: JsValue = response.json
(js \ "builds").as[List[Build]]
要修改一个字段,你可以这样做,例如:
val build = builds.head // get the first build
val modifiedBuild = build.copy(name = "new name")
然后将其转换回 JSON:
Json.toJson(mp)
我需要 Json 我的模型,但我有问题(我是初学者)。
我的模型
https://gist.github.com/anonymous/1c2e88cb83cbeace6f34
我需要让 json 进入我的模型 我需要 json-> 进行模型转换
我使用网络服务获取 json 以及如何为我的模型实现作业对象列表
控制器
https://gist.github.com/anonymous/c526483b29be0b198bca
我需要对象来编辑一些细节,我想重新转换为 Json
我的看法是这样的 我有新想法
谢谢...
看起来你几乎拥有你需要的一切。要将 JSON 中的 builds
转换为 Build
的列表,您可以这样做:
val js: JsValue = response.json
(js \ "builds").as[List[Build]]
要修改一个字段,你可以这样做,例如:
val build = builds.head // get the first build
val modifiedBuild = build.copy(name = "new name")
然后将其转换回 JSON:
Json.toJson(mp)