2012-06-16 3 views
0

안녕하세요, 안드로이드에서 사진을 보여주는 간단한 응용 프로그램을 구현하려고합니다.Picasa API 구문 분석 JSON 안드로이드 피드

많은 시련 끝에 이제 Google Java API 클라이언트 (Gdata가 아닌)를 사용하여 Picasa 피드를 가져옵니다. 내 프로그램에서

, 피드의 JSON의 첫 번째 레이어 필드 (예 : version 아래의 코드에서 encoding가) 성공적으로 매핑 될 수 있으므로 공급 및 연결 아무 문제 그러나 나는 두 번째 레이어를 매핑 할 수 없습니다 생각하지 필드를 객체로 가져옵니다.

저는 albumFeed = response.parseAs(AlbumFeed.class); 을 사용하여 파서를 호출합니다. 공식 샘플에서

나는이 AlbumFeed.java List <AlbumEntry> feed으로

public class AlbumFeed { 

     // cannot be List 
     @Key 
     List<AlbumEntry> feed; 

     @Key 
     String version; 

     @Key 
     String encoding; 

} 

있다; 나는 목록 내가 ArrayList<AlbumEntry> feed 로 변경 오류가 표시되지 않습니다하지만 ArrayList를가 비어 있습니다

06-16 14:35:10.789: E/AndroidRuntime(1129): Caused by: java.lang.IllegalArgumentException: unable to create new instance of class java.util.List because it is an interface and because it has no accessible default constructor

시작할 수없는 말을이 오류를 얻을 것이다. 누구든지 주어진 JsonObjectParser를 사용하여 JSON을 Object에 매핑하는 정확한 방법을 알려 줄 수 있습니까?

많은 감사 사람이 내 질문에 대답 할 수 있다면

더 CODE

public class newApiActivity extends Activity { 

    HttpTransport transport = AndroidHttp.newCompatibleTransport(); 
    static final JsonFactory JSON_FACTORY = new JacksonFactory(); 

    public static HttpRequestFactory createRequestFactory(HttpTransport transport) { 
    return transport.createRequestFactory(new HttpRequestInitializer() { 
     public void initialize(HttpRequest request) { 

     // final JsonCParser jsoncparser = new JsonCParser(JSON_FACTORY); 

     request.setParser(new JsonObjectParser(GSON_FACTORY)); 
     // request.setParser(jsoncparser); 



     GoogleHeaders headers = new GoogleHeaders(); 
     headers.setApplicationName("APOD/1.0"); 
     headers.setGDataVersion("2"); 
     request.setHeaders(headers); 
     } 
    }); 
    } 




public void mainLogic(){ 
HttpRequest buildGetRequest = reqFactory.buildGetRequest(url); 

     HttpResponse response = buildGetRequest.execute(); 
     albumFeed = response.parseAs(AlbumFeed.class); 

} 

}

AlbumEntry.java는 같은 내가 동작을 테스트하기 위해 XMLNS을 복용하고있을 것입니다 경우)

public class AlbumEntry extends Entry { 

    @Key("xmlns") 
    public String xmlns; 


    } 

JSON 피드 자체는 다음과 같습니다.

{"version":"1.0","encoding":"UTF-8", 
"feed":{"xmlns":"http://www.w3.org/2005/Atom","xmlns$gphoto":"http://schemas.google.com/photos/2007,……}} 

답변

0

어리석은 날. 안드로이드/피카사 API 문맥과는 아무런 관련이 없습니다.

GSON 설명서에서 더 많은 내용을 읽고 나면 json 객체에 따라 {}은 맵이되지만 배열이 아닙니다. 배열이 목록에 매핑 할 수 있지만,지도 내가 AlbumFeed.java 그것은 작업을 시작

간단한

@Key AlbumEntry feed;

로 변경 객체로 매핑 또는

지도 할 수있다.

GSON에 좋은 참조가 여기 Converting JSON to Java

입니다