如何使用scala反序列化包含@@的json字符串 [英] how to deserialize a json string that contains @@ with scala'

查看:77
本文介绍了如何使用scala反序列化包含@@的json字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题已经说明的那样,我想反序列化包含以@@开头的键的json字符串.不幸的是,使用@@我的标准方法(使用案例类)不再起作用.

As the title already explains, I would like to deserialize a json string that contains a key that starts with @@. With the @@ my standard approach using case classes sadly does not work anymore.

val test = """{"@@key": "value"}"""
case class Test(@@key: String) // not possible
val gson =  new GsonBuilder().create()
val res = gson.fromJson(test, classOf[Test])

如何在不预处理输入json字符串的情况下使用@@?

How can work with the @@ withtout preprocessing the input json string?

推荐答案

最简单的答案是引用字段名称:

The simplest answer is to quote the field name:

case class Test(`@@key`: String)

这篇关于如何使用scala反序列化包含@@的json字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆