英文:
Parsing json correctly using GSON and Java
问题
以下是您要翻译的内容:
public class Result {
String id, user_id, title, first_name, last_name, gender, dob, email, phone,
website, address, status;
Links _links;
}
public class Links {
Link self, edit, avatar;
}
public class Link {
String href;
}
英文:
This is my json string as I want to convert it to Java Class:
"result": {
"id": "39559",
"first_name": "John",
"last_name": "Who",
"gender": "male",
"dob": null,
"email": "john.who@roberts.com",
"phone": null,
"website": null,
"address": null,
"status": "active",
"_links": {
"self": {
"href": "https://gorest.co.in/public-api/users/39559"
},
"edit": {
"href": "https://gorest.co.in/public-api/users/39559"
},
"avatar": {
"href": null
}
}
}
And this is my class (I removed the getters and toString):
public class Result {
String id, user_id, title, first_name, last_name, gender, dob, email, phone,
website, address, status, _links, album_id, url, thumbnail, post_id, name, body;
}
I wonder how can I represent
"_links": {
"self": {
"href": "https://gorest.co.in/public-api/users/39559"
},
"edit": {
"href": "https://gorest.co.in/public-api/users/39559"
},
"avatar": {
"href": null
}
}
How can I represent the missing part in my Result class?
答案1
得分: 0
_links
似乎是一个具有self
、edit
和avatar
属性的JSON对象。这些属性中的每一个也都是JSON对象,都具有href
属性。→ 您需要这三个类来表示这些对象:
public class Result {
String id, user_id, title, first_name, last_name, gender;
String dob, email, phone, website, address, status;
String album_id, url, thumbnail, post_id, name, body;
Links _links;
}
public class Links {
Link self, edit, avatar;
}
public class Link {
String href;
}
英文:
_links
seems to be a JSON Object with attributes self
, edit
and avatar
. Each of these attributes are JSON Objects too, all having attribute href
. → You need these three classes for representing those objects:
public class Result {
String id, user_id, title, first_name, last_name, gender;
String dob, email, phone, website, address, status;
String album_id, url, thumbnail, post_id, name, body;
Links _links;
}
public class Links {
Link self, edit, avatar;
}
public class Link {
String href;
}
答案2
得分: 0
你需要创建一个具有字段的链接对象。
英文:
you need to create Links as object with fields
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论