【发布时间】:2013-01-16 22:23:47
【问题描述】:
如何在 Play 中替换 JSON 值中的值?
代码说明:
def newReport() = Action(parse.json) { request =>
var json = request.body
if((json \ "customerId").as[Int] == -1){
// replace customerId after some logic to find the new value
}
json.validate[Report](Reports.readsWithoutUser).map {
case _: Report =>
【问题讨论】:
-
您不会操纵 json 字符串。在那条路上充满了疯狂。您将 json 字符串转换为本机数据结构,操作该结构,然后重新编码为 json。
-
点赞 MarcB,或使用 Json Coast2Coast 功能 mandubian.com/2012/10/29/…
-
如果my answer对您有帮助,请选择它作为接受的答案。
标签: json scala playframework-2.0 playframework-2.1