从Scala中的JsValue删除键 [英] Remove a key from a JsValue in Scala
本文介绍了从Scala中的JsValue删除键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能是一个非常简单的问题,但是我很难找到一个干净/可行的解决方案. 我只想从我拥有的json对象中删除一个字段. 假设我有:
It's probably a very easy question but I'm having trouble finding a clean/working solution. I just want to remove a field from a json object I have. Let's say I have :
val body:Option[JsValue] = request.body.asJson
身体外观:
{
"url": "www.google.com",
"id": "123",
"count" : 1,
"label" : "test"
}
,我想从中删除字段"id".
and I want to remove the field "id" from it.
我已阅读> http://www.playframework.com/documentation/2.1.1/ScalaJsonTransformers 案例6,但不幸的是无法完全理解它. (我对Scala和函数式编程非常陌生)
I have read http://www.playframework.com/documentation/2.1.1/ScalaJsonTransformers case#6 but unfortunately couldn't fully understand it. (I'm pretty new to Scala and functional programming)
谢谢!
推荐答案
这可以作为JsObject
来完成,它扩展了JsValue
:
This can be done as a JsObject
, which extends JsValue
:
body.as[JsObject] - "id"
这篇关于从Scala中的JsValue删除键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文