2015-10-31 136 views
1

當我從數據庫中檢索列表時,我得到「預期的BEGIN_ARRAY,但是在第1行第1列路徑$」STRING。如何解決這個問題,我錯誤地在我的代碼..事先感謝。

我越來越

JSON響應低於,

[{ 
    "eventId":1, 
    "ringeeUserId":2, 
    "text":"Reception1", 
    "place":"Erode", 
    "eventDate":"2015-10-03", 
    "startTime":"09:00 AM", 
    "endTime":"12:00 PM", 
    "isActive":0, 
    "isDelete":0, 
    "eventUserRelationBOs":[] 
    }] 

EventBO類文件下面,

package com.ringeeapp.service.businessobjects; 

    import java.io.Serializable; 
    import java.util.List; 

    public class EventBO implements Serializable { 

    private static final long serialVersionUID = 281625146097131515L; 

    private long eventId; 

    private long ringeeUserId; 

    private String text; 

    private String place; 

    private String eventDate; 

    private String startTime; 

    private String endTime; 

    private int isActive; 

    private int isDelete; 

    private List<EventUserRelationBO> eventUserRelationBOs; 

    public long getEventId() { 
     return eventId; 
    } 

    public void setEventId(long eventId) { 
     this.eventId = eventId; 
    } 

    public long getRingeeUserId() { 
     return ringeeUserId; 
    } 

    public void setRingeeUserId(long ringeeUserId) { 
     this.ringeeUserId = ringeeUserId; 
    } 

    public String getText() { 
     return text; 
    } 

    public void setText(String text) { 
     this.text = text; 
    } 

    public String getPlace() { 
     return place; 
    } 

    public void setPlace(String place) { 
     this.place = place; 
    } 

    public String getEventDate() { 
     return eventDate; 
    } 

    public void setEventDate(String eventDate) { 
     this.eventDate = eventDate; 
    } 

    public String getStartTime() { 
     return startTime; 
    } 

    public void setStartTime(String startTime) { 
     this.startTime = startTime; 
    } 

    public String getEndTime() { 
     return endTime; 
    } 

    public void setEndTime(String endTime) { 
     this.endTime = endTime; 
    } 

    public int getIsDelete() { 
     return isDelete; 
    } 

    public void setIsDelete(int isDelete) { 
     this.isDelete = isDelete; 
    } 

    public int getIsActive() { 
     return isActive; 
    } 

    public void setIsActive(int isActive) { 
     this.isActive = isActive; 
    } 

    public List<EventUserRelationBO> getEventUserRelationBOs() { 
     return eventUserRelationBOs; 
    } 

    public void setEventUserRelationBOs(List<EventUserRelationBO> eventUserRelationBOs) { 
     this.eventUserRelationBOs = eventUserRelationBOs; 
    } 

} 

下面的代碼,過程JSON數據

public @ResponseBody String getAllInvites(@RequestParam("userBO") String userBo) { 
     List<EventBO> eventBOs = new ArrayList<EventBO>(); 
     UserBO userBO = gson.fromJson(userBo, UserBO.class); 
     try { 
      eventBOs = manageEventServiceImpl.getAllInvites(userBO); 
      log.info("getting all events for user " + userBO.getRingeeUserId()); 
     } catch (UserServiceException serExp) { 
      log.error("Error while getting event for userId id" + userBO.getRingeeUserId(), serExp); 
     } 
     return gson.toJson(eventBOs); 
    } 
+0

我猜你在這裏發佈的JSON不完全是你試圖解析的JSON - 你確定你做了一個確切的副本? – Nitek

+0

是的,它是一個確切的副本 –

+0

請顯示您用於處理JSON數據的代碼。 – Wormbo

回答

0

您有一個數組的EventBO,但試圖閱讀爲對象。如果您解組這樣的:

EventBO bo = gson.fromJson(JSON, EventBO.class); 

比你會收到錯誤「java.lang.IllegalStateException:在行預計BEGIN_OBJECT但BEGIN_ARRAY 1列2路$」

,但如果更改代碼:

EventBO[] list = gson.fromJson(JSON, EventBO[].class); 

你成功解組此JSON

PS測試與Gson 2.4

+0

感謝您的迴應我有「預計BEGIN_ARRAY,但STRING在1行1列路徑$」問題如何解決該錯誤..... –

相關問題