我嘗試響應嵌套的JSON數據解析,但我不能。下面的代碼是我嵌套的json。在android中嵌套的Json解析
{
"Result": [
{
"Stock": {
"ID": 1,
"Code": "sample string 2",
"SerialNo": "sample string 3",
"RFID": "sample string 4",
"PairCode": "sample string 5",
"Barcode": "sample string 6",
"Name": "sample string 7",
"Description": "sample string 8",
"Model": "sample string 9",
"CategoryId": 1,
"BrandId": 1,
"ClassificationId": 1
},
"Division": {
"ID": 1,
"Name": "sample string 2",
"ParentID": 1,
"Path": "sample string 3"
},
"User": {
"ID": 1,
"Name": "sample string 2",
"Username": "sample string 3",
"Password": "sample string 4"
}
},
{
"Stock": {
"ID": 1,
"Code": "sample string 2",
"SerialNo": "sample string 3",
"RFID": "sample string 4",
"PairCode": "sample string 5",
"Barcode": "sample string 6",
"Name": "sample string 7",
"Description": "sample string 8",
"Model": "sample string 9",
"CategoryId": 1,
"BrandId": 1,
"ClassificationId": 1
},
"Division": {
"ID": 1,
"Name": "sample string 2",
"ParentID": 1,
"Path": "sample string 3"
},
"User": {
"ID": 1,
"Name": "sample string 2",
"Username": "sample string 3",
"Password": "sample string 4"
}
},
{
"Stock": {
"ID": 1,
"Code": "sample string 2",
"SerialNo": "sample string 3",
"RFID": "sample string 4",
"PairCode": "sample string 5",
"Barcode": "sample string 6",
"Name": "sample string 7",
"Description": "sample string 8",
"Model": "sample string 9",
"CategoryId": 1,
"BrandId": 1,
"ClassificationId": 1
},
"Division": {
"ID": 1,
"Name": "sample string 2",
"ParentID": 1,
"Path": "sample string 3"
},
"User": {
"ID": 1,
"Name": "sample string 2",
"Username": "sample string 3",
"Password": "sample string 4"
}
}
],
"RecordCount": 1
}
而且這是我的響應等級
public class ResultResponseModel<T>{
public int RecordCount;
public T Result[];
public int getRecordCount() {
return RecordCount;
}
public void setRecordCount(int recordCount) {
RecordCount = recordCount;
}
public T[] getResult() {
return Result;
}
public void setResult(T[] result) {
Result = result;
}
}
其他類
public class ServiceStockDivisionUserModel {
public ServiceStockDivisionUserModel()
{
Stock = new ServiceStockModel();
Division = new ServiceDivisionModel();
User = new ServiceUserModel();
}
public ServiceStockModel Stock ;
public ServiceDivisionModel Division ;
public ServiceUserModel User ;
public ServiceStockModel getStock() {
return Stock;
}
public void setStock(ServiceStockModel stock) {
Stock = stock;
}
public ServiceDivisionModel getDivision() {
return Division;
}
public void setDivision(ServiceDivisionModel division) {
Division = division;
}
public ServiceUserModel getUser() {
return User;
}
public void setUser(ServiceUserModel user) {
User = user;
}
}
我嘗試播服務後,投我JSON ResultResponseModel tockDivisionUserMopdel來獲取對象。但我無法施展,任何人都可以幫助我。謝謝。
我的理由:
JSONObject jsonObj = new JSONObject(responseModel.responseString);
Gson gson = new Gson();
listResultResponseModel = gson.fromJson(String.valueOf(jsonObj), ResultResponseModel.class);
可能重複的[如何在Android中解析JSON](http://stackoverflow.com/questions/9605913/how-to-parse-json-in-android) –
哦,當然不是 – artemitSoft
你能告訴我原因呢? –