enter code here
在获取这些详细信息时出现了空指针异常
"order": 8,
"month": "November",
"amount": "450",
"given": "450",
"date": "12-Sep-2018".
您能告诉我如何通过改型获得这种JSON格式的数据吗? 请告诉我我找不到这个问题的任何解决方案 { “状态”:1, “ msg”:“已成功找到数据..!”, “数据”:[ { “主题”:“学费”, “序列”:1, “月”:{ “ 7”:{ “订单”:7 “ month”:“十月”, “数量”:“ 450”, “给定”:“ 450”, “ date”:“ 2018年9月12日”, “状态”:“付费” }, “ 8”:{ “订单”:8 “ month”:“ 11月”, “数量”:“ 450”, “给定”:“ 450”, “ date”:“ 2018年9月12日”, “状态”:“付费” }, “ 9”:{ “订单”:9 “ month”:“ December”, “数量”:“ 200”, “给定”:null, “状态”:“到期” }, “ 10”:{ “订单”:10, “ month”:“ January”, “数量”:“ 450”, “给定”:null, “状态”:“到期” }, “ 11”:{ “订单”:11 “ month”:“ February”, “数量”:“ 450”, “给定”:null, “状态”:“到期” }, “ 12”:{ “订单”:12 “ month”:“ March”, “数量”:“ 450”, “给定”:null, “状态”:“到期” } } }, { “主题”:“运输费”, “序列”:2 “月”:{ “ 7”:{ “订单”:7 “ month”:“十月”, “ amount”:“ 400.00”, “给定”:“ 400”, “ date”:“ 2018年9月12日”, “状态”:“付费” }, “ 8”:{ “订单”:8 “ month”:“ 11月”, “数量”:“ 400”, “给定”:“ 400”, “ date”:“ 2018年9月12日”, “状态”:“付费” }, “ 9”:{ “订单”:9 “ month”:“ December”, “数量”:“ 400”, “给定”:null, “状态”:“到期” }, “ 10”:{ “订单”:10, “ month”:“ January”, “ amount”:“ 400.00”, “给定”:null, “状态”:“到期” }, “ 11”:{ “订单”:11 “ month”:“ February”, “ amount”:“ 400.00”, “给定”:null, “状态”:“到期” }, “ 12”:{ “订单”:12 “ month”:“ March”, “ amount”:“ 400.00”, “给定”:null, “状态”:“到期” } } }, { “主题”:“其他费用”, “序列”:3, “月”:{ “ 1”:{ “订单”:1 “ month”:“ Back_dues”, “金额”:300, “给定”:0, “状态”:“到期” } } }, { “ subject”:“ computer_test22”, “序列”:4 “月”:{ “ 1”:{ “订单”:1 “ month”:“ April”, “数量”:“ 100”, “给定”:“ 0”, “状态”:“到期” }, “ 2”:{ “订单”:2 “ month”:“ May”, “数量”:“ 100”, “给定”:“ 0”, “状态”:“到期” }, “ 3”:{ “订单”:3, “ month”:“ June”, “数量”:“ 100”, “给定”:“ 0”, “状态”:“到期” }, “ 4”:{ “订单”:4 “ month”:“ July”, “数量”:“ 100”, “给定”:“ 0”, “状态”:“到期” }, “ 5”:{ “订单”:5 “ month”:“ August”, “数量”:“ 100”, “给定”:“ 0”, “状态”:“到期” }, “ 6”:{ “订单”:6 “ month”:“ September”, “数量”:“ 100”, “给定”:“ 0”, “状态”:“到期” }, “ 7”:{ “订单”:7 “ month”:“十月”, “数量”:“ 100”, “给定”:“ 0”, “状态”:“到期” }, “ 8”:{ “订单”:8 “ month”:“ 11月”, “数量”:“ 100”, “给定”:“ 0”, “状态”:“到期” }, “ 9”:{ “订单”:9 “ month”:“ December”, “数量”:“ 100”, “给定”:“ 0”, “状态”:“到期” }, “ 10”:{ “订单”:10, “ month”:“ January”, “数量”:“ 100”, “给定”:“ 0”, “状态”:“到期” }, “ 11”:{ “订单”:11 “ month”:“ February”, “数量”:“ 100”, “给定”:“ 0”, “状态”:“到期” }, “ 12”:{ “订单”:12 “ month”:“ March”, “数量”:“ 100”, “给定”:“ 0”, “状态”:“到期” } } } ], “当前状态”: { “ subject”:“本月-(7月)”, “数量”:8750, “给定”:1700, “剩余”:7050, “状态”:“到期” } }
答案 0 :(得分:0)
使用Gson映射,这将是解决此问题的简便方法。
答案 1 :(得分:0)
首先,根据响应类型使用序列化创建相关模型。 例如:
@SerializedName("status")
private String status;
@SerializedName("msg")
private String msg;
之后,使用上述字符串创建默认构造函数和第二个构造函数。之后,您可以根据使用的值来创建getter和setter。
public "ClassName"(
String status,
String msg) {
this.status = status;
this.msg = msg;
}
public String getstatus() {
return status;
}
public String getmsg() {
return msg;
}
public void setStatus(String status) {
this.status = status;
}
public void setMsg(String msg) {
this.msg = msg;
}
答案 2 :(得分:0)
在这种情况下,我使用了Gson映射并完成了操作。
Ex:“主题”:“运输费”, “序列”:2 “月”:{ “ 7”:{
@SerializedName(“ subject”) 私有ArrayList subectList;
在主题模型中:
@SerializedName(“ Transport”) 私有字符串传输;
@SerializedName(“ sequence”) 私有int序列;
@SerializedName(“ months”) 私人ArrayList月;