0

첫 번째 클라이언트 서버 android 애플리케이션을 개발 중입니다. 즉, 안드로이드 애플리케이션은 서버 데이터베이스에서 클라이언트에 의해 제출 된 제품의 수를 알아 내려고 요청한다. 서버가 다음 데이터를 문자열로 Android 애플리케이션에 보냅니다.서버 응답의 Json 비 직렬화

// 서버가이 형식으로 클라이언트에 응답을 보냅니다.

{productid : 1, productname : Google Nexus 5, productdescription : 새 휴대 전화, productimage : Nexus 5.jpg, 입찰일 : 14-Feb-14 7:30:00 PM, currentdate : 14-Feb-14 11:57:41 AM, productrate : 33500} {productid : 5, productname : Samsung Galaxy Ace, 제품 설명 : 중고 휴대 전화, productimage : Ace.jpg, 입찰 : 2 월 15 일 오후 7:30:00, currentdate : 14-Feb-14 11:57:41 AM, productrate : 8500}

위의 코드는 서버가 2 개의 제품에 대한 세부 정보를 보낼 때 출력됩니다. 나는 아래의 모든 세부 사항을 분리하고 목록보기로 표시해야합니다. 서버에서 응답으로 n 개의 제품이 있으면 목록보기에 n 개의 항목이 있습니다. 목록보기 및 해당 코딩 작업을 알고 있습니다. 하지만이 서버 응답을 처리하는 방법을 모르겠습니다.

productid[0]=1 
productname[0]=Google Nexus 5 
productdescription[0]=New Mobile Phone //this should be first item in the list 
productimagename[0]=Nexus 5.jpg 
biddate[0]=14-Feb-14 7:30:00 PM 
currentdate[0]=14-Feb-14 11:57:41 AM 
productrate[0]=33500 

//similarly 
productid[1]=5   //this is the second item to be displayed in the list view 
productname[1]=Samsung Galaxy Ace 
productdescription[1]=Used Mobile Phone 
productimagename[1]=Ace.jpg 
biddate[1]=15-Feb-14 7:30:00 PM 
currentdate[1]=14-Feb-14 11:57:41 AM 
productrate[1]=8500 

json deserializing을 사용하여이 작업을 수행 할 수 있다고 들었습니다. 그러나 나는 그것을 어떻게하는지 모른다. 하나는 ..

답변

1
Class ProductInfo{ 
     String productdescription; 
     String productid; 
     String productname; 
     String productimagename; 
     String biddate; 
     String currentdate; 
     String productrate; 
} 
Class ProductListInfo 
{ 
    ArrayList<ProductInfo> productList = new ArrayList<ProductInfo>(); 
} 

    public void parseResponse(Object response) 
    { 
     GSonBuilder gsonBuilder = new GSonBuilder(); 
     GSon gson = gsonBuilder.create(); 
     ProductListInfo listOfProducts = new ProductListInfo(); 
     listOfProducts = gson.fromJson((String)response, ProductListInfo.class) 

    }