내 사용자 정의 클래스의 데이터가 표시되지 않습니다.JSONObject를 사용자 정의 클래스로 구문 분석
내가 PHP 스크립트에서 내 JSON 개체를 얻을 내가 문자열 result
에 저장 한 후 나는 GET 방식으로 특정 변수를 호출하는 클래스에서 내 사용자 정의 클래스 Planets
에 삽입하려고하지만 그것은에 표시되지 않습니다 내
String jsonString = result;
Gson gson = new Gson();
Planets seznamPlanet = gson.fromJson(jsonString, Planets.class);
this.result_tv.setText(seznamPlanet.getPlanetName());
//this.result_tv.setText(jsonString); this works
내 수업은 다음과 같습니다 :
public class Planets {
public String name;
public Integer size;
public Integer o2;
public Integer atmosphere;
public String getPlanetName() {
return name;
}
public Integer getPlanetSize() {
return size;
}
public Integer getPlanetO2() {
return o2;
}
public Integer getPlanetAtmosphere() {
return atmosphere;
}
}
텍스트 뷰
result_tv
여기
코드입니다 결과 문자열 내부
및 JSON 객체는 다음과 같습니다
public class Planet {
public String name;
public Integer size;
public Integer o2;
public Integer atmosphere;
}
(충돌을 피하기 위해) Planet
에 Planets
클래스의 이름을 바꿉니다
{"Planets":[{"name":"Earth","size":"3","o2":"1","atmosphere":"1"},{"name":"Mars","size":"8","o2":"0","atmosphere":"0"}]}
당신은 행성의 목록이 포함 된 또 하나 개의 클래스가 필요 – cy3er