有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java需要BEGIN_数组,但在第1行第16列path$处是BEGIN_对象。地点[0]

响应类代码

public class LocationHealth implements HealthStatusIdentifiable{

@SerializedName("health")
int health;
@SerializedName("location")
String location;
@SerializedName("company")
String company;
@SerializedName("pos")
CompanyPos companyPos;
@SerializedName("rosters")
RosterHealth rosterHelath;
@SerializedName("cafe_tabs")
CafeHealth cafeHealth;


public int getHealth() {
    return health;
}

public void setHealth(int health) {
    this.health = health;
}

public String getLocation() {
    return location;
}

public void setLocation(String location) {
    this.location = location;
}

public String getCompany() {
    return company;
}

public void setCompany(String company) {
    this.company = company;
}

public CompanyPos getCompanyPos() {
    return companyPos;
}

public void setCompanyPos(CompanyPos companyPos) {
    this.companyPos = companyPos;
}

public RosterHealth getRosterHelath() {
    return rosterHelath;
}

public void setRosterHelath(RosterHealth rosterHelath) {
    this.rosterHelath = rosterHelath;
}

public CafeHealth getCafeHealth() {
    return cafeHealth;
}

public void setCafeHealth(CafeHealth cafeHealth) {
    this.cafeHealth = cafeHealth;
}

@Override
public String toString() {
    return location+" : "+company+" : "+health;
}

@Override
public int getHealthStatus() {
    if(health==100){
        return GOOD;
    }else if(health>50){
        return WARN;
    }else
        return ALERT;
}

}

公司。java/

 public class CompanyPos implements HealthStatusIdentifiable{

@SerializedName("inactive")
int inactive;
@SerializedName("active")
int active;
@SerializedName("name")
String name;
@SerializedName("health")
int health;


public int getTotal(){
    return inactive+active;
}

public int getInactive() {
    return inactive;
}

public void setInactive(int inactive) {
    this.inactive = inactive;
}

public int getActive() {
    return active;
}

public void setActive(int active) {
    this.active = active;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public int getHealth() {
    return health;
}

public void setHealth(int health) {
    this.health = health;
}

@Override
public int getHealthStatus() {
    if(inactive==0)
        return GOOD;
    if(inactive==1)
        return WARN;
    else
        return ALERT;
} }

JSON格式

{ "locations": [ { "pos": { "inactive": 7, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "FS-Cafeteria-Bangalore", "company": "FirstSource", "location_id": 1, "company_id": 1 }, { "pos": { "inactive": 1, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "Cafe-Hyderabad", "company": "General Electric", "location_id": 19, "company_id": 5 }, { "pos": { "inactive": 1, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "Shankar Narayan Building", "company": "Infinera", "location_id": 84, "company_id": 22 }, { "pos": { "inactive": 1, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "RMZ Eco Space", "company": "Northern Trust", "location_id": 82, "company_id": 70 }, { "pos": { "inactive": 2, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "SMS", "company": "Genpact", "location_id": 79, "company_id": 67 }, { "pos": { "inactive": 1, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "Surya Tech Park", "company": "Genpact", "location_id": 78, "company_id": 67 }, { "pos": { "inactive": 2, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "Pritech", "company": "Genpact", "location_id": 77, "company_id": 67 }, { "pos": { "inactive": 1, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "BNGLO.G-ETAMIN -CSR", "company": "Qualcomm", "location_id": 70, "company_id": 2 }, { "pos": { "inactive": 2, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "Aneja Towers", "company": "FirstSource", "location_id": 69, "company_id": 1 }, { "pos": { "inactive": 3, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "TECCI Park", "company": "FirstSource", "location_id": 68, "company_id": 1 }, { "pos": { "inactive": 2, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "ETA PARK-Chennai", "company": "FirstSource", "location_id": 67, "company_id": 1 }, { "pos": { "inactive": 1, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "Prestige Solitaire Building", "company": "Infinera", "location_id": 44, "company_id": 22 }, { "pos": { "inactive": 1, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "RMZ Eco World", "company": "Epicor", "location_id": 2, "company_id": 3 }, { "pos": { "inactive": 2, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "TVH Agnitio Park", "company": "Qualcomm", "location_id": 20, "company_id": 2 }, { "pos": { "inactive": 2, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "ABB-BTP", "company": "ABB", "location_id": 8, "company_id": 7 }, { "pos": { "inactive": 2, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "GE-Bengaluru", "company": "General Electric", "location_id": 5, "company_id": 5 }, { "pos": { "inactive": 3, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "BNGLO.E", "company": "Qualcomm", "location_id": 15, "company_id": 2 }, { "pos": { "inactive": 1, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "BNGLO.D", "company": "Qualcomm", "location_id": 14, "company_id": 2 }, { "pos": { "inactive": 3, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "BNGLO.C", "company": "Qualcomm", "location_id": 13, "company_id": 2 }, { "pos": { "inactive": 3, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "INDIA. N & T", "company": "Qualcomm", "location_id": 12, "company_id": 2 }, { "pos": { "inactive": 1, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "BNGLO.B", "company": "Qualcomm", "location_id": 11, "company_id": 2 }, { "pos": { "inactive": 1, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "BNGLO. H- Vector", "company": "Qualcomm", "location_id": 10, "company_id": 2 }, { "pos": { "inactive": 1, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "Britannia Cafe", "company": "Britannia", "location_id": 17, "company_id": 8 }, { "pos": { "inactive": 4, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "BT- Ecoworld", "company": "British Telecom", "location_id": 7, "company_id": 6 }, { "pos": { "inactive": 2, "active": 0 }, "health": 66, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "BT- Pritech", "company": "British Telecom", "location_id": 6, "company_id": 6 }, { "pos": { "active": 0, "inactive": 0 }, "health": 100, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "ABB-HEBBAL", "company": "ABB", "location_id": 85, "company_id": 7 }, { "pos": { "active": 0, "inactive": 0 }, "health": 100, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "Corporate", "company": "Corporate", "location_id": 4, "company_id": 4 }, { "pos": { "active": 0, "inactive": 0 }, "health": 100, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "Paladion Cafe", "company": "Paladion", "location_id": 18, "company_id": 9 }, { "pos": { "active": 0, "inactive": 0 }, "health": 100, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "Mystifly", "company": "Mystifly", "location_id": 81, "company_id": 68 }, { "pos": { "active": 0, "inactive": 0 }, "health": 100, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "Whitefield", "company": "Technicolor", "location_id": 80, "company_id": 69 }, { "pos": { "active": 0, "inactive": 0 }, "health": 100, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "TEK MEDOWS-Chennai", "company": "FirstSource", "location_id": 66, "company_id": 1 }, { "pos": { "active": 0, "inactive": 0 }, "health": 100, "rosters": { "attended": 0, "rosters": 0 }, "cafe_tabs": { "live_tabs": 0, "total_cafe_tabs": 0 }, "location": "Bagmane Tech Park", "company": "Qualcomm", "location_id": 86, "company_id": 2 } ] }

Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 16 path $.locations[0]


共 (2) 个答案

  1. # 2 楼答案

    你的映射不正确。您的响应表明您得到了一个包含数组的对象

    添加这个类

    public class MyResponse{
    @SerialisedName("locations")
        List< LocationHealthResponse > locationHealthList;
    }
    

    你的电话是Call<MyResponse> getResponse()而不是Call<LocationHealth> getResponse()