Lift-json 将带有 'type' 字段的 json 提取到一个案例类中 [英] Lift-json extract json with 'type' field into a case class
本文介绍了Lift-json 将带有 'type' 字段的 json 提取到一个案例类中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 Lift-json 将 JSON 提取到案例类中.这是我的案例类:
I am trying to extract JSON into a case class using lift-json. Here is my case class:
case class Person(name: String, age: Int)
这里是json
{ "name": "Some Name", "age": 24, type: "Student" }
如何将 type
字段提取到实例 Person
中?
How can I extract the type
field into an instance Person
?
json.extract[Person]
推荐答案
反引号允许您使用保留名称.
Backticks allow you to use reserved names.
case class Person(name:String, age:Int, `type`:String)
这篇关于Lift-json 将带有 'type' 字段的 json 提取到一个案例类中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文