Java关键字与JSON字段定义冲突:unexpected token

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/LucasXu01/article/details/84798666

若是JSON中定义的字段名使用了Java中的关键字,不准许在JavaBean中定义,可以使用@SerializedName注解:

@SerializedName(switch)
private String myswitch;
@SerializedName(“app_version_code”)
private int versionCode;

说明:JSON字符串中的字段switch对应Javabean中的字段myswitch

亦有其他解决方案:https://blog.csdn.net/zml_2015/article/details/53994902

猜你喜欢

转载自blog.csdn.net/LucasXu01/article/details/84798666