나는 baidu 음악 웹 api에서 정보를 얻고 싶다. 나는 견인 아래 링크를 사용 http://openapi.baidu.com/rest/2.0/music/billboard/billlist?page_size=50×tamp=2016-09-22+18%3A47%3A54&sign=b2e34bd4b6c19a065d5a7e49e591a41b&session_key=9mzdDcHtDENrxP3Spvk7ZFbNHNijT8l8fN%2BfI%2Fe3U5rh3U5g%2FDVvjZyqB48aJaYO5qaqw4JbugF79hgAQ%2FGBIixUSuaP&type=21&page_no=1다른 json 결과를 처리하는 방법
유일한 유형이 다릅니다. 하나는 23이고 다른 하나는 21입니다. return jason의 경우 : 하나는 billboard21이고 다른 하나는 billboard23입니다. retrofit2를 사용하여 API를 액세스하고 jason을 파싱하는 경우이 두 가지 리턴을 처리 할 두 개의 서로 다른 Java 클래스를 정의해야합니까? 17 가지 유형이 있습니다. 17 가지 Java 클래스를 만들지 않으려면 어떻게해야합니까?
내 액세스 API는 다음과 같습니다
@GET("/rest/2.0/music/billboard/billlist")
Call<BaiduBillListContainer> getBillList(@Query("timestamp") String timestamp,
@Query("type") String type,
@Query("sign") String sign,
@Query("session_key") String sessionkey,
@Query("page_size") String pagesize,
@Query("page_no") String pageno);
BaiduBillListContainer.java 정의 :
public class BaiduBillListContainer implements Serializable {
BaiduBillList billboard21;
public BaiduBillList getBillBoardInfo() {
return billboard21;
}
public void setBillBoardInfo(BaiduBillList billBoardInfo) {
this.billboard21 = billBoardInfo;
}
}
는 billboard23 수익을 가져 오는 데 사용할 수 없습니다. 어느 누구도이 질문에 대해 저를 도울 수 있습니까? 매우 감사합니다.
는이 로컬 DB를 만들었나요? 예를 선택하면 하나의 메인 테이블과 다른 서브 테이블을 생성 할 수 있습니다. Main Table 모든 정보를 포함합니다. 서브 테이블은 고유 ID 및 유형을 포함합니다. 따라서 모든 세부 사항에 대해 하나의 클래스 만 생성하고 unique_id 및 유형이 –
인 17 개의 하위 클래스를 생성해야합니다. 다른 json 키를 구문 분석하기 위해 다른 Java 클래스를 선언해야합니다. –
jsonObject (retrofit 사용)를 수신하고이를 동적으로 어레이로 변환 할 수 있습니다 그것으로부터 jsonArray를 얻은 후에 pojo의. 이 답변을 확인할 수 있습니다 (http://stackoverflow.com/questions/24279245/how-to-handle-dynamic-json-in-retrofit#answer-28576252). –