使用保留关键字作为变量名创建Java对象 [英] Creating Java Object with reserved keywords as variable name

查看:779
本文介绍了使用保留关键字作为变量名创建Java对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有需要转换为Java对象的JSON.我需要处理的JSON如下所示:

I have JSON that needs to be converted to a Java Object. The JSONs I need to handle can look like this:

{
    "documents": [
        {
        "title": "Jobs",
        "is-saved": false,
        "abstract": "<span class=\"hit\">Jobs</span> may refer to:\n\n* Steve <span class=\"hit\">Jobs</span> (1955–2011), co-founder and former CEO of consumer electronics company...<br />",
        "id": "Jobs",
        "url": "http://en.wikipedia.org/wiki/Jobs"
        }
    ],

   "keywords_local": [
       {
        "keyword": "Jobs",
        "interest": 1,
        "angle": 0
       }
   ],
   "sessionid": "6cd6402e-1f67-45a8-b0fa-e79a5d0d50f4",
   "q": "Jobs",
}

在搜索引擎(在本例中为"Jobs")中输入搜索关键字时,将返回此JSON.我还没有命名这些要创建的变量,这个JSON只是从一个类似的早期应用程序中送给"我的.因此,我显然在保存变量和抽象变量方面遇到了麻烦.摘要是一个保留关键字,在我读过的任何地方,保留关键字都不能用作变量名.

This JSON is returned when entering a search keyword on a searchengine, in this case "Jobs". I have not named these variables-to-be-created, this JSON was just "given" to me from a similar earlier app. So I'm obviously having trouble with variables is-saved and abstract. Abstract is a reserved keyword and everywhere I read a reserved keyword CANNOT be used as a variable name.

我没有访问我正在更新的前一个应用程序的权限,我想指出的是,我需要自己弄清楚;)但是我现在还是站不住脚,没有如何前进的想法.

I do not have access to the previous app that I am sort of updating and I guess the point to that is that I need to figure it out by myself ;) But I am a bit of a stand still now, have no idea of how to move forward.

我是新手,所以如果我问一个愚蠢的问题,请不要给我下地狱,这是我第一次编写任何类型的应用程序! ;) 感谢您的帮助!

I'm a newbie, so do not give me hell if I'm asking a stupid question, it's my first time coding any sort of app! ;) Thanks for any help!

推荐答案

如果使用GSON进行解析,则可以根据需要命名成员并为映射添加注释.

If you use GSON for parsing you can name your members as you want and annotate them for mapping.

@SerializedName("abstract")
private String abstractText;

这篇关于使用保留关键字作为变量名创建Java对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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