- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
如何在嵌套的 json 响应后建模 java 对象。我正在尝试使用来自谷歌的 GSON 库来解析此响应,所以我想从 json 字符串转到 java
示例
Json 响应
{
"iamTicket": {
"ticket": "W1-104-Q36w4qw0hdklirrgtuioqbp",
"userId": "13748569064",
"userIdPseudonym": null,
"agentId": "839298462",
"realmId": null,
"authenticationLevel": "20",
"identityAssuranceLevel": null,
"namespaceId": "50000003",
"role": [],
"access": "",
"scoped": null,
"authTime": null
},
"userExtInfo": {
"user": {
"userId": null,
"username": null,
"userType": null,
"namespaceId": null,
"password": null,
"securityLevel": null,
"challengeQuestionAnswer": [],
"umRole": null,
"credentialStatus": null,
"fullName": [],
"displayName": [],
"characteristics": null,
"address": [],
"phone": [
{
"parentId": null,
"debugInfo": null,
"id": null,
"type": "MOBILE",
"primary": null,
"phoneNumber": "7603042083",
"status": null
}
],
"email": {
"id": null,
"type": null,
"primary": null,
"address": "mhaddad@apple.com",
"status": null
},
"alternateEmail": [],
"i18NAttribute": null,
"creditCard": [],
"preferredCCId": null,
"isRecoveryInfoSet": null,
"taxIdentifier": []
},
"authOfferingUsage": null,
"realmIds": [],
"grant": [],
"taxStatus": []
},
"needContactInfoUpdate": false,
"altAuthInfoSet": true,
"action": "CHALLENGE",
"riskLevel": "MED"
}
这是我为响应创建的 Java 对象:
IUSAuth.java
package com.apple.confedential.internal.helper;
public class IUSAuth {
public IUSAuth() {}
IAMTicket iamTicket;
UserExtInfo userExtInfo;
Boolean needContactInfoUpdate;
Boolean altAuthInfoSet;
String action;
String riskLevel;
public static class IAMTicket {
String ticket;
String userId;
Integer userIdPseudonym;
String agentId;
String realmId;
String authenticationLevel;
Integer identityAssuranceLevel;
String namespaceId;
String[] role;
String access;
Integer scoped;
Integer authTime;
public String getTicket() {
return ticket;
}
public void setTicket(String ticket) {
this.ticket = ticket;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public Integer getUserIdPseudonym() {
return userIdPseudonym;
}
public void setUserIdPseudonym(Integer userIdPseudonym) {
this.userIdPseudonym = userIdPseudonym;
}
public String getAgentId() {
return agentId;
}
public void setAgentId(String agentId) {
this.agentId = agentId;
}
public String getRealmId() {
return realmId;
}
public void setRealmId(String realmId) {
this.realmId = realmId;
}
public String getAuthenticationLevel() {
return authenticationLevel;
}
public void setAuthenticationLevel(String authenticationLevel) {
this.authenticationLevel = authenticationLevel;
}
public Integer getIdentityAssuranceLevel() {
return identityAssuranceLevel;
}
public void setIdentityAssuranceLevel(Integer identityAssuranceLevel) {
this.identityAssuranceLevel = identityAssuranceLevel;
}
public String getNamespaceId() {
return namespaceId;
}
public void setNamespaceId(String namespaceId) {
this.namespaceId = namespaceId;
}
public String[] getRole() {
return role;
}
public void setRole(String[] role) {
this.role = role;
}
public String getAccess() {
return access;
}
public void setAccess(String access) {
this.access = access;
}
public Integer getScoped() {
return scoped;
}
public void setScoped(Integer scoped) {
this.scoped = scoped;
}
public Integer getAuthTime() {
return authTime;
}
public void setAuthTime(Integer authTime) {
this.authTime = authTime;
}
}
public static class UserExtInfo {
User user;
String authOfferingUsage;
RealmIds[] realmIds;
Grant[] grant;
TaxStatus[] taxStatus;
public static class User{
String userId;
String username;
String userType;
String namespaceId;
String password;
String securityLevel;
String[] challengeQuestionAnswer;
String umRole;
String credentialStatus;
String[] fullName;
String[] displayName;
String characteristics;
String[] address;
Phone phone;
Email email;
AlternateEmail[] alternateEmail;
String i18NAttribute;
String[] creditCard;
String preferredCCId;
String isRecoveryInfoSet;
String taxIdentifier;
public static class AlternateEmail {
}
public static class Email {
String id;
String type;
String primary;
String address;
String status;
}
public static class Phone {
String parentId;
String debugInfo;
String id;
String type;
String primary;
String phoneNumber;
String status;
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public String getDebugInfo() {
return debugInfo;
}
public void setDebugInfo(String debugInfo) {
this.debugInfo = debugInfo;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getPrimary() {
return primary;
}
public void setPrimary(String primary) {
this.primary = primary;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getUserType() {
return userType;
}
public void setUserType(String userType) {
this.userType = userType;
}
public String getNamespaceId() {
return namespaceId;
}
public void setNamespaceId(String namespaceId) {
this.namespaceId = namespaceId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSecurityLevel() {
return securityLevel;
}
public void setSecurityLevel(String securityLevel) {
this.securityLevel = securityLevel;
}
public String[] getChallengeQuestionAnswer() {
return challengeQuestionAnswer;
}
public void setChallengeQuestionAnswer(String[] challengeQuestionAnswer) {
this.challengeQuestionAnswer = challengeQuestionAnswer;
}
public String getUmRole() {
return umRole;
}
public void setUmRole(String umRole) {
this.umRole = umRole;
}
public String getCredentialStatus() {
return credentialStatus;
}
public void setCredentialStatus(String credentialStatus) {
this.credentialStatus = credentialStatus;
}
public String[] getFullName() {
return fullName;
}
public void setFullName(String[] fullName) {
this.fullName = fullName;
}
public String[] getDisplayName() {
return displayName;
}
public void setDisplayName(String[] displayName) {
this.displayName = displayName;
}
public String getCharacteristics() {
return characteristics;
}
public void setCharacteristics(String characteristics) {
this.characteristics = characteristics;
}
public String[] getAddress() {
return address;
}
public void setAddress(String[] address) {
this.address = address;
}
public Phone getPhone() {
return phone;
}
public void setPhone(Phone phone) {
this.phone = phone;
}
}
public static class RealmIds{
}
public static class Grant{
}
public static class TaxStatus{
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getAuthOfferingUsage() {
return authOfferingUsage;
}
public void setAuthOfferingUsage(String authOfferingUsage) {
this.authOfferingUsage = authOfferingUsage;
}
public RealmIds[] getRealmIds() {
return realmIds;
}
public void setRealmIds(RealmIds[] realmIds) {
this.realmIds = realmIds;
}
public Grant[] getGrant() {
return grant;
}
public void setGrant(Grant[] grant) {
this.grant = grant;
}
public TaxStatus[] getTaxStatus() {
return taxStatus;
}
public void setTaxStatus(TaxStatus[] taxStatus) {
this.taxStatus = taxStatus;
}
}
}
然后我想用google的GSON库解析获取票据数据:
public String parseIUSResponse(String jsonResponse) {
Gson gson = new Gson();
IUSAuth response = gson.fromJson(jsonResponse, IUSAuth.class);
// How to get ticket from iamticket object??
return "";
}
有人可以帮帮我吗?
最佳答案
从对象的角度思考。该 JSON 字符串中有两个对象。所有其他属性都是内部对象或属性。
package com.apple.internal.helper;
public class IUSAuth {
IAMTicket iamTicket;
UserExtInfo userExtInfo;
public IUSAuth() {}
public class IAMTicket {
// ADD ALL YOUR IAMTicket Properties Here
String ticket;
}
public class UserExtInfo{
// ADD ALL YOUR USEREXTINFO Properties here
}
}
关于java - 如何在嵌套的 Json 响应后对 Java 类建模,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27475722/
我正在寻找可以从 Eclipse 的 UML 图生成代码的工具。该工具应该从 UML 图生成代码,进行逆向工程以查看代码更改,并提供合并选项以防止因任何更改而删除文件。 是否有工具可以做到这一点,或者
我正在寻找有关建模的见解。我有一个关于设计模式和基本类图、序列图和用例的介绍类(class)。 我发现类图作为我编程中的组织工具非常宝贵。到目前为止,用例还算有用。 本学期我正在上课,更深入地学习 U
如何使用 flutter 数据建模技术访问“HH”和“mm”。我一直在尝试按以下方式使用它,但是下面给出了错误。 我的数据模型当前为它的简化版本。 class Week { final Strin
我正在使用 Neo4j 和 PHP。在我的项目中,我有餐厅节点。每个节点都有纬度、经度和分类属性。 我需要返回与用户给定分类相匹配的餐厅节点,其结果按距用户位置的距离排序(即第一个最近的餐厅)。 最简
我希望 POJO 包含一个 Status 字段(只有两个可能的值 SUCCESS、FAILED),并且根据此状态,第二个字段需要为 POJO 对象(如果 Status 为 SUCCESS) 或只是字符
我正在尝试将我的办公室迁移到数据库应用程序中。这是我得到的: (来源:phunkei.de) 公司和个人从客户继承(1:1关系)。这是因为他们都可以是“客户”并收到账单,我想引用订单中的单个表。公司和
我目前有这个数据库结构: 一个条目可以有多个"file"、“文本”和“url”类型的项目。 这些项目中的每一项在文本、网址或文件表(存储数据的位置)中都有一个对应的项目。 我需要一个查询来有效地选择一
下面的代码不应该像“if(condition)”语句一样工作吗,当它在另一个循环中并且“body”有自己的 break 或 continue 语句时,会出现明显的错误行为: for( ; condit
我一直在像这样存储和递增下载计数器: INCRBY downloads: 1 但现在我想要下载:* 按值排序,以便显示热门下载列表。 我觉得我可以更好地存储它。我愚弄了: ZINCRBY downlo
我开始使用图形数据库,在我的团队中,我们已经开始为我们的软件建模图形。当我们尝试“记录”模型以查看数据库的结构时,问题就出现了。对于 SQL 数据库,您只需查看 SQL 模式。 我们花了一些时间阅读
我正在做一个固定效应回归并且遇到了自相关问题,为了解决这个问题,我正在使用预测、lmtest 和 plm 包进行 ARIMA 建模。我的数据是一般面板数据,looks like this ,我正在尝试
我想知道是否有任何工具可以帮助我对 C 应用程序(即函数式编程)进行建模。例如。我目前正在构建一个共享库。但是为了直观地传达我的设计,我需要类似 UML 的东西。我想这样做,以便审查我的设计的人不需要
我正在尝试将 JSON 转换为 GSON ,但我无法建模。谁能给我举个例子。 [ { "id": "1", "name": "lalala",
正如标题所说,在 中建模 optional 参数的最佳方法是什么?斯卡拉 ? 对于 optional 参数,我的意思是执行函数体不需要的值。 要么因为该参数存在默认值,要么根本不需要该参数本身(例如配
我发现 UML 可用于记录 OO 系统的各个方面,尤其是用于整体架构的类图和用于说明特定例程的序列图。我想为我的 clojure 应用程序做同样的事情。我目前对模型驱动开发不感兴趣,只是在交流应用程序
我想知道是否有人知道如何使用 UML 在属性中建模 DateTime 基元类型? 最佳答案 我想这取决于日期的格式......请参阅下面的示例,其中我使用两个整数(分别为日和年)和一个名为“Month
我有一些与我的问题建模相关的问题。我正在研究基于模型的测试的论文项目。还想从专家的角度了解我是否采用正确的方法来建模我的场景。我正在对 Android 应用程序的 UI 进行建模,遍历它们,生成测试用
我正在尝试建立对 CouchDB 以及如何为某些现实世界场景建模数据的理解。我现在已经尽可能多地“按日期获取我的博客文章”;) 给定这样的文件: { "_id": "couch1",
一个模型资源是如何分层的?例如假设一个人有一个“留言板”并且“消息”是一种资源。假设“消息”可以有回复,从而形成一个讨论线程。如何模拟线程的概念? “消息”是否包含它的子项? “线程”是它自己的资源吗
我正在尝试创建一个像通用 POJO 一样工作的对象,因为我必须通过不同的对象传递它,并且我需要一个接口(interface)来访问其属性。 目前,我使用具有 getField 方法的基础对象来完成此操
我是一名优秀的程序员,十分优秀!