RT,在用gson解析的时候报错 Caused by: com.google.gson.stream.MalformedJsonException: Unterminated object at line 7 column 8 path $.results[0].illness_name
我的doctor类定义如下
*/
public class Doctor {
private int id;
private String illness_name;
private String doctor_name;
private String hospital_name;
private String head_image;
private String personal_website;
private String doctor_intro;
解析gson的代码如下
private void initData() {
Gson gson = new Gson();
Type userType = new TypeToken<ResponseResult<List<Doctor>>>() {
}.getType();
ResponseResult<List<Doctor>> result = gson.fromJson(results, userType);
Log.d("result","-------------->"+results);
System.out.println("-----------------"+results);
doctors = result.getResults();
final DoctorListAdapter doctorListAdapter = new DoctorListAdapter(DoctorListActivity.this, (ArrayList<Doctor>) doctors,this);
lv_doctors.setAdapter(doctorListAdapter);
lv_doctors.setSelection(0);
}
json数据如下
private static final String results = "{\n" +
" \"error\": false,\n" +
" \"results\": [\n" +
" {\n" +
" \"id\": \"1\",\n" +
" \"illness_name\":\"功能神经外科\"\n" +
" \"doctor_name\":\"胡勇生\"\n" +
" \"hospital_name\":\"玄武医院\"\n" +
" \"head_image\":\"http://...\"\n" +
" \"personal_website\":\"http://...\"\n" +
" \"doctor_intro\":\"擅长:三叉神经痛。。。。。。。。。。。\"\n" +
" },\n" +
" {\n" +
" \"id\": \"1\",\n" +
" \"illness_name\":\"功能神经外科\"\n" +
" \"doctor_name\":\"胡勇生\"\n" +
" \"hospital_name\":\"玄武医院\"\n" +
" \"head_image\":\"http://...\"\n" +
" \"personal_website\":\"http://...\"\n" +
" \"doctor_intro\":\"擅长:三叉神经痛。。。。。。。。。。。\"\n" +
" },\n" +
" {\n" +
" \"id\": \"1\",\n" +
" \"illness_name\":\"功能神经外科\"\n" +
" \"doctor_name\":\"胡勇生\"\n" +
" \"hospital_name\":\"玄武医院\"\n" +
" \"head_image\":\"http://...\"\n" +
" \"personal_website\":\"http://...\"\n" +
" \"doctor_intro\":\"擅长:三叉神经痛。。。。。。。。。。。\"\n" +
" },\n" +
" {\n" +
" \"id\": \"1\",\n" +
" \"illness_name\":\"功能神经外科\"\n" +
" \"doctor_name\":\"胡勇生\"\n" +
" \"hospital_name\":\"玄武医院\"\n" +
" \"head_image\":\"http://...\"\n" +
" \"personal_website\":\"http://...\"\n" +
" \"doctor_intro\":\"擅长:三叉神经痛。。。。。。。。。。。\"\n" +
" },\n" +
" {\n" +
" \"id\": \"1\",\n" +
" \"illness_name\":\"功能神经外科\"\n" +
" \"doctor_name\":\"胡勇生\"\n" +
" \"hospital_name\":\"玄武医院\"\n" +
" \"head_image\":\"http://...\"\n" +
" \"personal_website\":\"http://...\"\n" +
" \"doctor_intro\":\"擅长:三叉神经痛。。。。。。。。。。。\"\n" +
" },\n" +
" {\n" +
" \"id\": \"1\",\n" +
" \"illness_name\":\"功能神经外科\"\n" +
" \"doctor_name\":\"胡勇生\"\n" +
" \"hospital_name\":\"玄武医院\"\n" +
" \"head_image\":\"http://...\"\n" +
" \"personal_website\":\"http://...\"\n" +
" \"doctor_intro\":\"擅长:三叉神经痛。。。。。。。。。。。\"\n" +
" },\n" +
" {\n" +
" \"id\": \"1\",\n" +
" \"illness_name\":\"功能神经外科\"\n" +
" \"doctor_name\":\"胡勇生\"\n" +
" \"hospital_name\":\"玄武医院\"\n" +
" \"head_image\":\"http://...\"\n" +
" \"personal_website\":\"http://...\"\n" +
" \"doctor_intro\":\"擅长:三叉神经痛。。。。。。。。。。。\"\n" +
" },\n" +
" {\n" +
" \"id\": \"1\",\n" +
" \"illness_name\":\"功能神经外科\"\n" +
" \"doctor_name\":\"胡勇生\"\n" +
" \"hospital_name\":\"玄武医院\"\n" +
" \"head_image\":\"http://...\"\n" +
" \"personal_website\":\"http://...\"\n" +
" \"doctor_intro\":\"擅长:三叉神经痛。。。。。。。。。。。\"\n" +
" },\n" +
" {\n" +
" \"id\": \"1\",\n" +
" \"illness_name\":\"功能神经外科\"\n" +
" \"doctor_name\":\"胡勇生\"\n" +
" \"hospital_name\":\"玄武医院\"\n" +
" \"head_image\":\"http://...\"\n" +
" \"personal_website\":\"http://...\"\n" +
" \"doctor_intro\":\"擅长:三叉神经痛。。。。。。。。。。。\"\n" +
" },\n" +
" {\n" +
" \"id\": \"1\",\n" +
" \"illness_name\":\"功能神经外科\"\n" +
" \"doctor_name\":\"胡勇生\"\n" +
" \"hospital_name\":\"玄武医院\"\n" +
" \"head_image\":\"http://...\"\n" +
" \"personal_website\":\"http://...\"\n" +
" \"doctor_intro\":\"擅长:三叉神经痛。。。。。。。。。。。\"\n" +
" },\n" +
" {\n" +
" \"id\": \"1\",\n" +
" \"illness_name\":\"功能神经外科\"\n" +
" \"doctor_name\":\"胡勇生\"\n" +
" \"hospital_name\":\"玄武医院\"\n" +
" \"head_image\":\"http://...\"\n" +
" \"personal_website\":\"http://...\"\n" +
" \"doctor_intro\":\"擅长:三叉神经痛。。。。。。。。。。。\"\n" +
" },\n" +
" {\n" +
" \"id\": \"1\",\n" +
" \"illness_name\":\"功能神经外科\"\n" +
" \"doctor_name\":\"胡勇生\"\n" +
" \"hospital_name\":\"玄武医院\"\n" +
" \"head_image\":\"http://...\"\n" +
" \"personal_website\":\"http://...\"\n" +
" \"doctor_intro\":\"擅长:三叉神经痛。。。。。。。。。。。\"\n" +
" }\n" +
" ]\n" +
"}";
请问这到底是为什么啊??
분명히 이에 대응할 수 없습니다. Doctor는 jsonarray이고 그 위에 또 다른 레이어가 있습니다. 오류 및 결과에 대해서는 이 레이어에 해당하는 응답이 없습니다.
데이터 형식이 잘못되었습니다. 쉼표가 누락되었습니다
으아아아권장되는 테스트 방법은 문자열을 로컬에서 연결하여 테스트하는 것이 아니라 온라인 JSON 검증 도구를 통해 직접 테스트하여 json 데이터 검증을 우선시하는 것입니다.
백엔드나 다른 소스에서 제공하는 json 문자열의 정확성을 확인한 후 GSON 파싱 오류의 원인을 비교해 보세요.
먼저 json 데이터가 합법적인지 확인해주세요
gson 형식 도구를 사용하여 Bean 자동 생성