如何在Scala案例类中使用特殊字符

how to use special character in scala case class

我正在使用下面的JSON,

1
2
3
4
5
{
 "@context":"Testingcontext",
 "@type":"Testingtype",
 "actor":"Testingactor"
}

我要在scala中为其创建案例类的

1
case class LoggedInAction(`@context`: String,`@type`:String,actor:String)

如何在案例类中使用特殊字符,例如@&?另外,如何使用此类案例类字段?


与您在示例中所做的一样:

1
2
3
4
5
6
7
8
scala> case class LoggedInAction(`@context`: String,`@type`:String,actor:String)
defined class LoggedInAction

scala> val example = LoggedInAction("context","type","actor")
example: LoggedInAction = LoggedInAction(context,type,actor)

scala> example.`@context`
res0: String = context