Given a string of JSON, and a case class that corresponds to it, what's a simple way to parse the JSON into the case class? There are many libraries available, but it seems that Scala might now do this out of the box.

What about if the JSON should be parsed into a list of the case class?

UPDATE:

Jerkson seems to be abandoned, and I don't want to install the full Play or Lift framework or anything else heavy.

推荐答案

有几个框架可以做到这一点.

circe

现在用了很多.很多很棒的功能.会把cat 拉进来.

https://circe.github.io/circe/https://github.com/circe/circe

JSON4s

JSON4s is quite mature and supports jackson or a native JSON-Parser. Used it in many projects to replace jerkson.

https://github.com/json4s/json4s

play-json

Can be used without the full play stack. Great support as part of the play project at typesafe.

http://www.playframework.com/documentation/2.0/ScalaJson

Scala-Pickling

序列化框架.有一个选项可以序列化/反序列化为JSON.

https://github.com/scala/pickling

Spray JSON

Can searialize and deserialize. Need to know number of arguments for deserialization tough.

https://github.com/spray/spray-json

Json相关问答推荐

服务器不返回JSON

从json数组中删除特定元素

PowerShell脚本未按预期生成预期的JSON输出

JQ如何获取特定子元素的所有父母

通过在织女星简化图上裁剪来显示文本

使用json_query更新事实

Jolt-Json转换:通过引用标识符(而不是索引)设置值

如何使用jq使用子值对象的键对json对象进行分组

Ansible - 将文件内容添加到字典中

错误解析错误:意外令牌:在我的 .eslintrc.json 文件中.为什么?

jq json - 按键名 Select

如何从 json 中获取单个元素?

使用 JQ 从文件中删除重复的 JSON 块

boost::json::value 的大括号初始化将其从对象转换为数组

无法向 Json 数组添加新元素

如何使用 LINQ 在 C# 中重构对象?

如何使用 gson 将数据保存在 json 文件中?

如何在 Go 中生成带有排序键的 JSON?

JSON 语法错误:'unexpected number' 或 'JSON.parse: expected ',' or '}' after property value in object'

如何遍历 JSON 中的条目?