【发布时间】:2021-07-14 17:25:40
【问题描述】:
我在一个单独的文件中有这个 JSON:
{
"TestModel" : [
{"query" : "select * from ci_lmaggregation.elementstest where hash_aggregation_key = 0 ALLOW FILTERING "},
{"query" : "select * from ci_lmaggregation.elementstest where hash_aggregation_key = 1 ALLOW FILTERING "},
{"query" : "select * from ci_lmaggregation.elementstest where hash_aggregation_key = 2 ALLOW FILTERING "}
]
}
}
我正在尝试遵循他们的快速入门,但它甚至没有找到“decodeOption”、“Parse.parse”或其他任何内容。我很困惑?
val input_file = "[path]/FeatureMapping.json"
val json_content = scala.io.Source.fromFile(input_file).mkString
//it can't find decodeOption
val json_data = json_content.decodeOption[List[Person]].getOrElse(Nil)
//or Parse.parse (which should work given this http://argonaut.io/doc/parsing/)
val jdata = Parse.parse(json_content)
所以我不完全确定如何完成我想做的事情。我试过遵循这个: Parse JSON array using Scala Argonaut
还有他们网站上的入门指南,但似乎都没有像这里那样处理数组情况的示例。此外,SO 帖子中的代码示例 codec3 显示为不存在,所以我也很困惑。
我只是想要一个查询数组作为文件中的字符串,为什么没有像在 python 中那样的简单方法呢?
【问题讨论】:
标签: arrays json scala argonaut