大家好我有>>> any('bob' == j.name for j in i)
True
没有钥匙或者#34;标题"如下
JSONArray
如何访问数组中的每个对象,我看到的所有示例都包含列表前的标题或名称,但是这个没有名称,因此我可以在[
{
"messages_PK_ID": 429,
"messages_Name": "اختبار المنهج التأسيسي1",
"messages_ToSendDateDiff": 365,
"message_URL": "<p style=\"text-align: center;\"><a href=\"http://www.iacademypd.com/LevelExamLogin.aspx\"><img alt=\"\" src=\"http://iacademypd.com/AttachFiles/Level1.jpg\" /></a></p>",
"messageType_Name": "بطاقة",
"message_FKID_MessageType": 1,
"sendEmailAuditTrial_DayNo": 365,
"sendEmailAuditTrial_Type": 1,
"sendEmailAuditTrial_Datetime": "2012-02-24T10:05:39.587",
"messages_Year": 1,
"message_URL_New": "http://www.iacademypd.com/LevelExamLogin.aspx"
},
{
"messages_PK_ID": 428,
"messages_Name": "البطاقة/364",
"messages_ToSendDateDiff": 364,
"message_URL": "<p><img alt=\"\" src=\"http://iacademypd.com/AttachFiles/card-364aaa.jpg\" /></p>",
"messageType_Name": "بطاقة",
"message_FKID_MessageType": 1,
"sendEmailAuditTrial_DayNo": 364,
"sendEmailAuditTrial_Type": 1,
"sendEmailAuditTrial_Datetime": "2012-02-24T10:05:39.58",
"messages_Year": 1,
"message_URL_New": "http://iacademypd.com/AttachFiles/card-364aaa.jpg"
},....and so on
中指定< / p>
有什么建议吗?
答案 0 :(得分:0)
请将RoboPojo Generator用于Android Studio,它将帮助您为您创建模型类,并直接将SetData设置为您的模型类。
如果您使用Gson来设置数据。
在ilink下面帮助你:
https://github.com/robohorse/RoboPOJOGenerator
希望这会对你有所帮助。
答案 1 :(得分:0)
使用Gson Library解析这个json最简单的方法
compile 'com.google.code.gson:gson:2.8.1'
使用think来解析http://www.jsonschema2pojo.org/
你会得到像这样的pojo课程 的 1.User.Java 强>
public class User {
@SerializedName("messages_PK_ID")
@Expose
private Integer messagesPKID;
@SerializedName("messages_Name")
@Expose
private String messagesName;
@SerializedName("messages_ToSendDateDiff")
@Expose
private Integer messagesToSendDateDiff;
@SerializedName("message_URL")
@Expose
private String messageURL;
@SerializedName("messageType_Name")
@Expose
private String messageTypeName;
@SerializedName("message_FKID_MessageType")
@Expose
private Integer messageFKIDMessageType;
@SerializedName("sendEmailAuditTrial_DayNo")
@Expose
private Integer sendEmailAuditTrialDayNo;
@SerializedName("sendEmailAuditTrial_Type")
@Expose
private Integer sendEmailAuditTrialType;
@SerializedName("sendEmailAuditTrial_Datetime")
@Expose
private String sendEmailAuditTrialDatetime;
@SerializedName("messages_Year")
@Expose
private Integer messagesYear;
@SerializedName("message_URL_New")
@Expose
private String messageURLNew;
public Integer getMessagesPKID() {
return messagesPKID;
}
public void setMessagesPKID(Integer messagesPKID) {
this.messagesPKID = messagesPKID;
}
public String getMessagesName() {
return messagesName;
}
public void setMessagesName(String messagesName) {
this.messagesName = messagesName;
}
public Integer getMessagesToSendDateDiff() {
return messagesToSendDateDiff;
}
public void setMessagesToSendDateDiff(Integer messagesToSendDateDiff) {
this.messagesToSendDateDiff = messagesToSendDateDiff;
}
public String getMessageURL() {
return messageURL;
}
public void setMessageURL(String messageURL) {
this.messageURL = messageURL;
}
public String getMessageTypeName() {
return messageTypeName;
}
public void setMessageTypeName(String messageTypeName) {
this.messageTypeName = messageTypeName;
}
public Integer getMessageFKIDMessageType() {
return messageFKIDMessageType;
}
public void setMessageFKIDMessageType(Integer messageFKIDMessageType) {
this.messageFKIDMessageType = messageFKIDMessageType;
}
public Integer getSendEmailAuditTrialDayNo() {
return sendEmailAuditTrialDayNo;
}
public void setSendEmailAuditTrialDayNo(Integer sendEmailAuditTrialDayNo) {
this.sendEmailAuditTrialDayNo = sendEmailAuditTrialDayNo;
}
public Integer getSendEmailAuditTrialType() {
return sendEmailAuditTrialType;
}
public void setSendEmailAuditTrialType(Integer sendEmailAuditTrialType) {
this.sendEmailAuditTrialType = sendEmailAuditTrialType;
}
public String getSendEmailAuditTrialDatetime() {
return sendEmailAuditTrialDatetime;
}
public void setSendEmailAuditTrialDatetime(String sendEmailAuditTrialDatetime) {
this.sendEmailAuditTrialDatetime = sendEmailAuditTrialDatetime;
}
public Integer getMessagesYear() {
return messagesYear;
}
public void setMessagesYear(Integer messagesYear) {
this.messagesYear = messagesYear;
}
public String getMessageURLNew() {
return messageURLNew;
}
public void setMessageURLNew(String messageURLNew) {
this.messageURLNew = messageURLNew;
}
}
在解析了json之后,你必须像这样使用解析
Gson mGson=new Gson();
ArrayList<User> userArrayList=new ArrayList<>();
JsonArray jsonElements=new JsonArray("your Json Array");
for (int i = 0; i < jsonElements.size(); i++) {
User user=new User();
user=mGson.fromJson(jsonElements.get(i).getJsonObject().toString(),User.class);
userArrayList.add(user);
}
//你可以像这样访问 userArrayList.get(0).getMessagesName(); //第一个对象项目
如上所述,您可以访问响应pojo。