{"success":true,"errorMsg":"","result":{"rShipmentLists":[{"gasdescatthattime":"礦泉水","gasidatthattime":15,"count":1}],"rSendDetails":[{"affectCompName":"江岳公司","gasIdAtThattime":15,"gasDescAtThattime":"礦泉水","bottleSendCount":1,"bottleBackCount":1,"bottleSendCountAndDetail":{"count":1,"rNumberDetails":[{"number":"910000157"}]},"bottleBackCountAndDetail":{"count":1,"rNumberDetails":[{"number":"910000115"}]}}],"rBackShipmentLists":[{"gasdescatthattime":"礦泉水","gasidatthattime":15,"count":1}]}}
這樣的物件?
private List<RShipmentList> rShipmentLists;
private List<RSendDetail> rSendDetails;
private List<RShipmentList> rBackShipmentLists;
麻煩提供下決議的辦法,工具
uj5u.com熱心網友回復:
參考下這個String str = "{"URL":["url1","url2","url3"],"Title":["title1","title2","title3"]}";
try {
JSONObject object = new JSONObject(str);
JSONArray urlArray = object.getJSONArray("URL");
JSONArray titleArray = object.getJSONArray("Title");
for (int i = 0; i < urlArray.length(); i++) {
System.out.println(titleArray.getString(i));
}
} catch (JSONException e) {
e.printStackTrace();
}
uj5u.com熱心網友回復:
public class ResponseBean {
/**
* success : true
* errorMsg :
* result : {"rShipmentLists":[{"gasdescatthattime":"礦泉水","gasidatthattime":15,"count":1}],"rSendDetails":[{"affectCompName":"江岳公司","gasIdAtThattime":15,"gasDescAtThattime":"礦泉水","bottleSendCount":1,"bottleBackCount":1,"bottleSendCountAndDetail":{"count":1,"rNumberDetails":[{"number":"910000157"}]},"bottleBackCountAndDetail":{"count":1,"rNumberDetails":[{"number":"910000115"}]}}],"rBackShipmentLists":[{"gasdescatthattime":"礦泉水","gasidatthattime":15,"count":1}]}
*/
private boolean success;
private String errorMsg;
private ResultBean result;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getErrorMsg() {
return errorMsg;
}
public void setErrorMsg(String errorMsg) {
this.errorMsg = errorMsg;
}
public ResultBean getResult() {
return result;
}
public void setResult(ResultBean result) {
this.result = result;
}
public static class ResultBean {
private List<RShipmentListsBean> rShipmentLists;
private List<RSendDetailsBean> rSendDetails;
private List<RBackShipmentListsBean> rBackShipmentLists;
public List<RShipmentListsBean> getRShipmentLists() {
return rShipmentLists;
}
public void setRShipmentLists(List<RShipmentListsBean> rShipmentLists) {
this.rShipmentLists = rShipmentLists;
}
public List<RSendDetailsBean> getRSendDetails() {
return rSendDetails;
}
public void setRSendDetails(List<RSendDetailsBean> rSendDetails) {
this.rSendDetails = rSendDetails;
}
public List<RBackShipmentListsBean> getRBackShipmentLists() {
return rBackShipmentLists;
}
public void setRBackShipmentLists(List<RBackShipmentListsBean> rBackShipmentLists) {
this.rBackShipmentLists = rBackShipmentLists;
}
public static class RShipmentListsBean {
/**
* gasdescatthattime : 礦泉水
* gasidatthattime : 15
* count : 1
*/
private String gasdescatthattime;
private int gasidatthattime;
private int count;
public String getGasdescatthattime() {
return gasdescatthattime;
}
public void setGasdescatthattime(String gasdescatthattime) {
this.gasdescatthattime = gasdescatthattime;
}
public int getGasidatthattime() {
return gasidatthattime;
}
public void setGasidatthattime(int gasidatthattime) {
this.gasidatthattime = gasidatthattime;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
public static class RSendDetailsBean {
/**
* affectCompName : 江岳公司
* gasIdAtThattime : 15
* gasDescAtThattime : 礦泉水
* bottleSendCount : 1
* bottleBackCount : 1
* bottleSendCountAndDetail : {"count":1,"rNumberDetails":[{"number":"910000157"}]}
* bottleBackCountAndDetail : {"count":1,"rNumberDetails":[{"number":"910000115"}]}
*/
private String affectCompName;
private int gasIdAtThattime;
private String gasDescAtThattime;
private int bottleSendCount;
private int bottleBackCount;
private BottleSendCountAndDetailBean bottleSendCountAndDetail;
private BottleBackCountAndDetailBean bottleBackCountAndDetail;
public String getAffectCompName() {
return affectCompName;
}
public void setAffectCompName(String affectCompName) {
this.affectCompName = affectCompName;
}
public int getGasIdAtThattime() {
return gasIdAtThattime;
}
public void setGasIdAtThattime(int gasIdAtThattime) {
this.gasIdAtThattime = gasIdAtThattime;
}
public String getGasDescAtThattime() {
return gasDescAtThattime;
}
public void setGasDescAtThattime(String gasDescAtThattime) {
this.gasDescAtThattime = gasDescAtThattime;
}
public int getBottleSendCount() {
return bottleSendCount;
}
public void setBottleSendCount(int bottleSendCount) {
this.bottleSendCount = bottleSendCount;
}
public int getBottleBackCount() {
return bottleBackCount;
}
public void setBottleBackCount(int bottleBackCount) {
this.bottleBackCount = bottleBackCount;
}
public BottleSendCountAndDetailBean getBottleSendCountAndDetail() {
return bottleSendCountAndDetail;
}
public void setBottleSendCountAndDetail(BottleSendCountAndDetailBean bottleSendCountAndDetail) {
this.bottleSendCountAndDetail = bottleSendCountAndDetail;
}
public BottleBackCountAndDetailBean getBottleBackCountAndDetail() {
return bottleBackCountAndDetail;
}
public void setBottleBackCountAndDetail(BottleBackCountAndDetailBean bottleBackCountAndDetail) {
this.bottleBackCountAndDetail = bottleBackCountAndDetail;
}
public static class BottleSendCountAndDetailBean {
/**
* count : 1
* rNumberDetails : [{"number":"910000157"}]
*/
private int count;
private List<RNumberDetailsBean> rNumberDetails;
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public List<RNumberDetailsBean> getRNumberDetails() {
return rNumberDetails;
}
public void setRNumberDetails(List<RNumberDetailsBean> rNumberDetails) {
this.rNumberDetails = rNumberDetails;
}
public static class RNumberDetailsBean {
/**
* number : 910000157
*/
private String number;
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
}
}
public static class BottleBackCountAndDetailBean {
/**
* count : 1
* rNumberDetails : [{"number":"910000115"}]
*/
private int count;
private List<RNumberDetailsBeanX> rNumberDetails;
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public List<RNumberDetailsBeanX> getRNumberDetails() {
return rNumberDetails;
}
public void setRNumberDetails(List<RNumberDetailsBeanX> rNumberDetails) {
this.rNumberDetails = rNumberDetails;
}
public static class RNumberDetailsBeanX {
/**
* number : 910000115
*/
private String number;
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
}
}
}
public static class RBackShipmentListsBean {
/**
* gasdescatthattime : 礦泉水
* gasidatthattime : 15
* count : 1
*/
private String gasdescatthattime;
private int gasidatthattime;
private int count;
public String getGasdescatthattime() {
return gasdescatthattime;
}
public void setGasdescatthattime(String gasdescatthattime) {
this.gasdescatthattime = gasdescatthattime;
}
public int getGasidatthattime() {
return gasidatthattime;
}
public void setGasidatthattime(int gasidatthattime) {
this.gasidatthattime = gasidatthattime;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
}
}
uj5u.com熱心網友回復:
public class ResponseEntry {public boolean success;
public String errorMsg;
public ResultEntry result;
}
public class ResultEntry {
public List<ShipmentEntry> rShipmentLists;
public List<SendDetailEntry> rSendDetails;
public List<BackShipmentEntry> rBackShipmentLists;
}
public class ShipmentEntry {
public String gasdescatthattime;
public int gasidatthattime;
public float count;
}
public class SendDetailEntry {
public String affectCompName;
public int gasIdAtThattime;
public String gasDescAtThattime;
public float bottleSendCount;
public float bottleBackCount;
public BottleSendCountAndDetailEntry bottleSendCountAndDetail;
public BottleBackCountAndDetailEntry bottleBackCountAndDetail;
}
public class BottleSendCountAndDetailEntry {
public float count;
public List<NumberDetailEntry> rNumberDetails;
}
public class NumberDetailEntry {
public String number;
}
public class BottleBackCountAndDetailEntry {
public float count;
public List<NumberDetailEntry> rNumberDetails;
}
public class BackShipmentEntry {
public String gasdescatthattime;
public String gasidatthattime;
public float count;
}
toObject:版本自選,getJSONString回傳你的json字串
1、 build.gradle(Module) : implementation 'com.google.code.gson:gson:2.8.5'
2、 ResponseEntry response = new GsonBuilder().create().fromJson(getJSONString(),
new TypeToken<ResponseEntry>() {
}.getType());
uj5u.com熱心網友回復:
package com.hazz.kotlinmvp.mvp.model.bean
data class dataNice(
val errorMsg: String,
val result: Result,
val success: Boolean
)
data class Result(
val rBackShipmentLists: List<RBackShipmentLists>,
val rSendDetails: List<RSendDetail>,
val rShipmentLists: List<RShipmentLists>
)
data class RBackShipmentLists(
val count: Int,
val gasdescatthattime: String,
val gasidatthattime: Int
)
data class RShipmentLists(
val count: Int,
val gasdescatthattime: String,
val gasidatthattime: Int
)
data class RSendDetail(
val affectCompName: String,
val bottleBackCount: Int,
val bottleBackCountAndDetail: BottleBackCountAndDetail,
val bottleSendCount: Int,
val bottleSendCountAndDetail: BottleSendCountAndDetail,
val gasDescAtThattime: String,
val gasIdAtThattime: Int
)
data class BottleBackCountAndDetail(
val count: Int,
val rNumberDetails: List<RNumberDetailX>
)
data class RNumberDetail(
val number: String
)
data class BottleSendCountAndDetail(
val count: Int,
val rNumberDetails: List<RNumberDetail>
)
data class RNumberDetailX(
val number: String
)
var nice ="\"success\":true,\"errorMsg\":\"\",\"result\":{\"rShipmentLists\":[{\"gasdescatthattime\":\"礦泉水\",\"gasidatthattime\":15,\"count\":1}],\"rSendDetails\":[{\"affectCompName\":\"江岳公司\",\"gasIdAtThattime\":15,\"gasDescAtThattime\":\"礦泉水\",\"bottleSendCount\":1,\"bottleBackCount\":1,\"bottleSendCountAndDetail\":{\"count\":1,\"rNumberDetails\":[{\"number\":\"910000157\"}]},\"bottleBackCountAndDetail\":{\"count\":1,\"rNumberDetails\":[{\"number\":\"910000115\"}]}}],\"rBackShipmentLists\":[{\"gasdescatthattime\":\"礦泉水\",\"gasidatthattime\":15,\"count\":1}]}}"
// val turnsType = object : TypeToken<dataNice>() {}.type
// val turns = Gson().fromJson<dataNice>(nice, turnsType) //決議
inline fun <reified T> genericType() = object: TypeToken<T>() {}.type
fun parseJson(str:String){
val bean = Gson().fromJson(nice, dataNice::class.javaObjectType)
val turnsType = genericType<List<dataNice>>()
}
kotlin 給你寫了一個和java 一樣的 三種決議物體類自己工具直接實作超級快的
https://blog.csdn.net/trineashao/article/details/78601631
uj5u.com熱心網友回復:
http://www.bejson.com/json2javapojo/new/轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/129110.html
標籤:Android
