java 关键字变量,使用保留关键字作为变量名创建Java对象

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": "Jobs may refer to:\n\n* Steve Jobs (1955–2011), co-founder and former CEO of consumer electronics company...
",

"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",

}

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!

解决方案

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

@SerializedName("abstract")

private String abstractText;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值