com.google.gson.stream.MalformedJsonException:第1行第1273834列的未终止字符串

时间:2018-09-30 15:59:13

标签: android json retrofit2

我已经使用了翻版进行api解析。但是陷入了错误。我研究并尝试了所有可能的解决方案,但无法解决。日志中显示的完整json响应错误为com.google.gson.stream.MalformedJsonException: Unterminated string at line 1 column 1273834 path $.data[393].member_info[3].website  我已实现如下:

我的MembersApi界面是:

public interface MembersApi {
@GET("api/family_tree")
Call<SerialDTO> getMyJSON();
}

我已经按如下方式致电服务:

 MembersApi service = new RetrofitApiClient(getApplicationContext()).createService(MembersApi.class);

    Log.d(TAG, "Before" );
    Call<SerialDTO> call = service.getMyJSON();
    call.enqueue(new Callback<SerialDTO>() {
        @Override
        public void onResponse(Call<SerialDTO> call, Response<SerialDTO> response) {
              Log.d(TAG, "Before" + response.toString());
            if (response.isSuccessful()) {

                ArrayList<SerialData> data = response.body().getData();
                initGridView();
                progressBar.setVisibility(View.GONE);
            }
        }

        @Override
        public void onFailure(Call<SerialDTO> call, Throwable t) {
            Log.d("TAG Failure", "" + t);
        }
    });

我的Json格式如下:

 {
"status": 200,
"data": [{
        "club_id": 1,
        "club_name": "Name",
        "member_info": [{
                "id": 2,
                "title": "Abc",
                "image": "",
                "position": "Chairman",
                "description": "unknown",
                "email": "unknown @gmail.com",
                "landline": "0000000",
                "mobile": "00000000",
                "website": "techcaresoft.com",
                "address": "kjbm",
                "blood_group": "unknown blood_group",
                "facebook": "https://www.facebook.com/brainworkventure/",
                "viber": "0000000"
            }

        ]
    },
    {
        "club_id": 3,
        "club_name": "Name1",
        "member_info": [{
            "id": 400,
            "title": "Member",
            "image": "sdjnsd",
            "org_level_categories_id": "3",
            "position": "Memeber",
            "description": "unknown",
            "email": "unknown @gmail.com",
            "landline": "000000",
            "mobile": "00000000",
            "website": "brainworknepal.com",
            "address": "unknown",
            "blood_group": "unknown blood_group",
            "facebook": "https://www.facebook.com/",
            "viber": "00000"


        }]
    }
]
}

我的根模型类是

  public class SerialDTO{


@SerializedName("data")
private ArrayList<SerialData> data;

public ArrayList<SerialData> getData() {
    return data;
}

public void setData(ArrayList<SerialData> data) {
    this.data = data;
}
}

SerialData类如下:

 public class SerialData implements Parcelable {

@SerializedName("club_id")
String club_id;
@SerializedName("club_name")
String club_name;
@SerializedName("member_info")
ArrayList<Serial> serial;

public String getClub_id() {
    return club_id;
}

public void setClub_id(String club_id) {
    this.club_id = club_id;
}

public String getClub_name() {
    return club_name;
}

public void setClub_name(String club_name) {
    this.club_name = club_name;
}

public ArrayList<Serial> getSerial() {
    return serial;
}

public void setSerial(ArrayList<Serial> serial) {
    this.serial = serial;
}

protected SerialData(Parcel in) {
    club_id = in.readString();
    club_name = in.readString();
    serial = in.createTypedArrayList(Serial.CREATOR);
}

public static final Creator<SerialData> CREATOR = new Creator<SerialData>() 
{
    @Override
    public SerialData createFromParcel(Parcel in) {
        return new SerialData(in);
    }

    @Override
    public SerialData[] newArray(int size) {
        return new SerialData[size];
    }
};

@Override
public int describeContents() {
    return 0;
}

@Override
public void writeToParcel(Parcel parcel, int i) {
    parcel.writeString(club_id);
    parcel.writeString(club_name);
    parcel.writeTypedList(serial);
}
}

我的SerialClass如下所示:

public class Serial implements Parcelable {
@SerializedName("title")
String title;
@SerializedName("image")
String photos;
@SerializedName("position")
String position;

@SerializedName("description")
String desc;
@SerializedName("email")
String email;
@SerializedName("mobile")
String mobile;
@SerializedName("address")
String address;
@SerializedName("blood_group")
String bloodGroup;
@SerializedName("website")
String website;
@SerializedName("landline")
String landline;

@SerializedName("viber")
String viber;

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public String getPhotos() {
    return photos;
}

public void setPhotos(String photos) {
    this.photos = photos;
}

public String getPosition() {
    return position;
}

public void setPosition(String position) {
    this.position = position;
}

public String getDesc() {
    return desc;
}

public void setDesc(String desc) {
    this.desc = desc;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getMobile() {
    return mobile;
}

public void setMobile(String mobile) {
    this.mobile = mobile;
}

public String getAddress() {
    return address;
}

public void setAddress(String address) {
    this.address = address;
}

public String getBloodGroup() {
    return bloodGroup;
}

public void setBloodGroup(String bloodGroup) {
    this.bloodGroup = bloodGroup;
}

public String getWebsite() {
    return website;
}

public void setWebsite(String website) {
    this.website = website;
}

public String getLandline() {
    return landline;
}

public void setLandline(String landline) {
    this.landline = landline;
}

public String getViber() {
    return viber;
}

public void setViber(String viber) {
    this.viber = viber;
}

protected Serial(Parcel in) {
    title = in.readString();
    photos = in.readString();
    position = in.readString();
    desc = in.readString();
    email = in.readString();
    mobile = in.readString();
    address = in.readString();
    bloodGroup = in.readString();
   website = in.readString();
    landline = in.readString();
    viber = in.readString();
}

public static final Creator<Serial> CREATOR = new Creator<Serial>() {
    @Override
    public Serial createFromParcel(Parcel in) {
        return new Serial(in);
    }

    @Override
    public Serial[] newArray(int size) {
        return new Serial[size];
    }
};

@Override
public int describeContents() {
    return 0;
}

@Override
public void writeToParcel(Parcel parcel, int i) {
    parcel.writeString(title);
    parcel.writeString(photos);
    parcel.writeString(position);
    parcel.writeString(desc);
    parcel.writeString(email);
    parcel.writeString(mobile);
    parcel.writeString(address);
    parcel.writeString(bloodGroup);
    parcel.writeString(website);
    parcel.writeString(landline);
    parcel.writeString(viber);
}

0 个答案:

没有答案