java使用GSON反序列化嵌套JSON字符串
全部,,
我有以下JSON
输出/字符串(它是来自jiraapi的响应):
{
"expand": "names,schema",
"startAt": 0,
"maxResults": 50,
"total": 1,
"issues": [
{
"expand": "operations,versionedRepresentations,editmeta,changelog,transitions,renderedFields",
"id": "18200",
"self": "https://localhost/rest/api/2/issue/18200",
"key": "LS-1111",
"fields": {
"issuetype": {
"self": "https://localhost/rest/api/2/issuetype/3",
"id": "3",
"description": "A task that needs to be done.",
"iconUrl": "https://localhost/secure/viewavatar?size=xsmall&avatarId=10318&avatarType=issuetype",
"name": "Task",
"subtask": false,
"avatarId": 10318
},
"timespent": 21600,
"aggregatetimespent": 25200,
"resolution": null,
"customfield_11201": null,
"project": {
"self": "https://localhost/rest/api/2/project/10100",
"id": "10100",
"key": "PROJKEY",
"name": "ProjectABCD",
"avatarUrls": {
"48x48": "https://localhost/secure/projectavatar?pid=10100&avatarId=10600",
"24x24": "https://localhost/secure/projectavatar?size=small&pid=10100&avatarId=10600",
"16x16": "https://localhost/secure/projectavatar?size=xsmall&pid=10100&avatarId=10600",
"32x32": "https://localhost/secure/projectavatar?size=medium&pid=10100&avatarId=10600"
}
},
"issuelinks": [
{
"id": "16202",
"self": "https://localhost/rest/api/2/issueLink/16202",
"type": {
"id": "10003",
"name": "Relates",
"inward": "relates to",
"outward": "relates to",
"self": "https://localhost/rest/api/2/issueLinkType/10003"
}
}
]
}
}
]
}
我使用GSON
遍历元素并获取值。我在下面的“嵌套对象”示例中编写了POJO
类
http://www.javacreed.com/gson-deserialiser-example/
我可以得到元素值直到第二级。如:
我能够得到response.expand
,response.issues.get(0).expand
的值和其他值,直到这个级别。
如何获取response.issues.get(0).fields.issuetype.id
的值
我应该如何构造我的反序列化程序和POJO
类。请帮忙。谢谢
# 1 楼答案
试试这个-
AvatarUrls。java
示例。java
字段。java
问题。java
发布链接。java
Issuetype。java
项目。java
类型。java
现在,您可以将其测试为-
Main。java
结果是-