We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model类里的变量命名和返回JSON中的名字必须一样吗?现在如果命名不一样就不能正确解析JSON取到数据,请问有没有什么方法可以让两者命名可以不统一?比如JSON的description在代码里我只想命名为desc Model里面命名: public class ZhuangbiImage { public String description; public String image_url; } 返回JSON格式: "id": 204, "description": "\u4e0d\u80fd\u56e0\u4e3a\u6211\u8d85\u53ef\u7231\u4f60\u5c31\u6b3a\u8d1f\u6211\u554a", ... ... "image_url": "http:\/\/7xjzdd.com1.z0.glb.clouddn.com\/i\/2015-07-31-4c92424a38c5db9c01abd63203584e1d.png"
public class ZhuangbiImage { public String description; public String image_url; }
"id": 204, "description": "\u4e0d\u80fd\u56e0\u4e3a\u6211\u8d85\u53ef\u7231\u4f60\u5c31\u6b3a\u8d1f\u6211\u554a", ... ... "image_url": "http:\/\/7xjzdd.com1.z0.glb.clouddn.com\/i\/2015-07-31-4c92424a38c5db9c01abd63203584e1d.png"
The text was updated successfully, but these errors were encountered:
如果你自己来解析json比如Android自带的解析是可以这么做的,但如果你借助第三方比如gson,fastjson等恐怕不行
Sorry, something went wrong.
字段别名,这个需求使用第三方JSON库也是支持的。 例如如果你使用Gson来解析,你可以这么定义:
@SerializedName("description") private String desc;
fastjson也有类似的功能,请查阅对应库的文档
No branches or pull requests
Model类里的变量命名和返回JSON中的名字必须一样吗?现在如果命名不一样就不能正确解析JSON取到数据,请问有没有什么方法可以让两者命名可以不统一?比如JSON的description在代码里我只想命名为desc
Model里面命名:
public class ZhuangbiImage { public String description; public String image_url; }
返回JSON格式:
"id": 204, "description": "\u4e0d\u80fd\u56e0\u4e3a\u6211\u8d85\u53ef\u7231\u4f60\u5c31\u6b3a\u8d1f\u6211\u554a", ... ... "image_url": "http:\/\/7xjzdd.com1.z0.glb.clouddn.com\/i\/2015-07-31-4c92424a38c5db9c01abd63203584e1d.png"
The text was updated successfully, but these errors were encountered: