【发布时间】:2014-04-10 13:06:08
【问题描述】:
给定一个像这样的 JSON 数组:
{
"success": true,
"data": [
{
"id": 600,
"title": "test deal",
"e54cbe3a434d8e6": 54
},
{
"id": 600,
"title": "test deal",
"e54cbe3a434d8e6": 54
},
],
"additional_data": {
"pagination": {
"start": 0,
"limit": 100,
"more_items_in_collection": false
}
}
}
在我的 Play 2.2.2 应用程序中,使用 Scala JSON Reads Combinator,一切正常:
implicit val entityReader = Json.reads[Entity]
val futureJson: Future[List[Entity]] = futureResponse.map(
response => (response.json \ "data").validate[List[Entity]].get
现在的问题是名为“e54cbe3a434d8e6”的键,我想在我的对象中将其命名为“值”:
// This doesn't work, as one might expect
case class Entity(id: Long, title: String, e54cbe3a434d8e6: Long)
// I would like to use 'value' instead of 'e54cbe3a434d8e6'
case class Entity(id: Long, title: String, value: Long)
关于组合子 here 和 here 的信息很多,但我只想使用与 JSON 数组中的键名不同的字段名。有人可以帮我找到一种简单的方法吗?
我想这和JSON.writes有关?!
【问题讨论】:
标签: json scala playframework