鉴于我有一个Json结构如下:
{
"id" : "1B23423B",
"payload" : {
"list" : [ {
"name" : "test",
"data" : [ {
"value" : "Some html",
"type" : "html",
}, {
"value" : "some text",
"type" : "text"
}]
}]
}
}
是否有一些聪明的方法可以将包含字段名称的字符串数组转换为Scala转换,而无需为每个字符串值手动指定转换。
例如,我想要返回字符串(“id”,“value”):
{
"id" : "1B23423B",
"payload" : {
"list" : [ {
"data" : [ {
"value" : "Some html",
}, {
"value" : "some text",
}]
}]
}
}
(“data”)将返回:
{
"payload" : {
"list" : [ {
"data" : [ {
"value" : "Some html",
"type" : "html",
}, {
"value" : "some text",
"type" : "text"
}]
}]
}
}
等等。希望我的意图很明确 - 基本上,我想使用字符串数组作为Json结构的投影。实际结构要大得多(20多个字段),这就是为什么我不想从字符串“手动”映射每个变换的原因。
我目前正在使用Play的Json库来处理所有内容,所以最好是在该框架内运行的东西。