1
我一直在試圖解決JAXB json問題,但我似乎無法弄清楚什麼是錯誤的。我得到的消息是:Java - JSONObject文本必須以字符1處的'{'開始
Caused by: org.codehaus.jettison.json.JSONException: A JSONObject text must begin with '{' at character 1 of [{"id":"Daler Kampagne 2","operation":"UPDATE","VoiceIAQStats":{"id":3,"esdId":3,"esdName":"Daler Kampagne 2","nResourcesLoggedIn":0,"nTotalContacts":0,"nHandledContacts":0,"nAbandonedContacts":0,"nDequeuedContacts":0,"avgTalkDuration":0,"longestTalkDuration":0,"avgWaitDuration":0,"longestWaitDuration":0,"longestCurrentlyWaitingDuration":0,"nAvailResources":0,"nInSessionResources":0,"nUnavailResources":0,"nWorkResources":0,"nSelectedResources":0,"nWaitingContacts":0,"nAverageHandlingTimeLowThreshold":0.0,"nAverageHandlingTimeHighThreshold":0.0,"nAverageWaitingTimeLowThreshold":0.0,"nAverageWaitingTimeHighThreshold":0.0,"nAbandonedCallsLowThreshold":0,"nAbandonedCallsHighThreshold":0,"nDequeuedCallsLowThreshold":0,"nDequeuedCallsHighThreshold":0,"nSLAPercentageLowThreshold":0.0,"nSLAPercentageHighThreshold":0.0}},{"id":"Dialer Kampagne 1","operation":"UPDATE","VoiceIAQStats":{"id":2,"esdId":2,"esdName":"Dialer Kampagne 1","nResourcesLoggedIn":0,"nTotalContacts":0,"nHandledContacts":0,"nAbandonedContacts":0,"nDequeuedContacts":0,"avgTalkDuration":0,"longestTalkDuration":0,"avgWaitDuration":0,"longestWaitDuration":0,"longestCurrentlyWaitingDuration":0,"nAvailResources":0,"nInSessionResources":0,"nUnavailResources":0,"nWorkResources":0,"nSelectedResources":0,"nWaitingContacts":0,"nAverageHandlingTimeLowThreshold":0.0,"nAverageHandlingTimeHighThreshold":0.0,"nAverageWaitingTimeLowThreshold":0.0,"nAverageWaitingTimeHighThreshold":0.0,"nAbandonedCallsLowThreshold":0,"nAbandonedCallsHighThreshold":0,"nDequeuedCallsLowThreshold":0,"nDequeuedCallsHighThreshold":0,"nSLAPercentageLowThreshold":0.0,"nSLAPercentageHighThreshold":0.0}},{"id":"ICD01","operation":"UPDATE","VoiceIAQStats":{"id":1,"esdId":1,"esdName":"ICD01","nResourcesLoggedIn":0,"nTotalContacts":0,"nHandledContacts":0,"nAbandonedContacts":0,"nDequeuedContacts":0,"avgTalkDuration":0,"longestTalkDuration":0,"avgWaitDuration":0,"longestWaitDuration":0,"longestCurrentlyWaitingDuration":0,"nAvailResources":0,"nInSessionResources":0,"nUnavailResources":0,"nWorkResources":0,"nSelectedResources":0,"nWaitingContacts":0,"nAverageHandlingTimeLowThreshold":0.0,"nAverageHandlingTimeHighThreshold":0.0,"nAverageWaitingTimeLowThreshold":0.0,"nAverageWaitingTimeHighThreshold":0.0,"nAbandonedCallsLowThreshold":0,"nAbandonedCallsHighThreshold":0,"nDequeuedCallsLowThreshold":0,"nDequeuedCallsHighThreshold":0,"nSLAPercentageLowThreshold":0.0,"nSLAPercentageHighThreshold":0.0}}]
at org.codehaus.jettison.json.JSONTokener.syntaxError(JSONTokener.java:463)
at org.codehaus.jettison.json.JSONObject.<init>(JSONObject.java:204)
at org.codehaus.jettison.mapped.MappedXMLInputFactory.createJSONObject(MappedXMLInputFactory.java:59)
at org.codehaus.jettison.mapped.MappedXMLInputFactory.createXMLStreamReader(MappedXMLInputFactory.java:44)
... 148 more
這裏是我的課:
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class CiscoStatsResponse {
private String id;
private String operation;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getOperation() {
return operation;
}
public void setOperation(String operation) {
this.operation = operation;
}
}
VoiceIAQStats
package dk.netdesign.wallboard.dataprovider.uccxrest.domain;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class VoiceIAQStats {
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Integer getEsdId() {
return esdId;
}
public void setEsdId(Integer esdId) {
this.esdId = esdId;
}
public String getEsdName() {
return esdName;
}
public void setEsdName(String esdName) {
this.esdName = esdName;
}
public Integer getnResourcesLoggedIn() {
return nResourcesLoggedIn;
}
public void setnResourcesLoggedIn(Integer nResourcesLoggedIn) {
this.nResourcesLoggedIn = nResourcesLoggedIn;
}
public Integer getnTotalContacts() {
return nTotalContacts;
}
public void setnTotalContacts(Integer nTotalContacts) {
this.nTotalContacts = nTotalContacts;
}
public Integer getnHandledContacts() {
return nHandledContacts;
}
public void setnHandledContacts(Integer nHandledContacts) {
this.nHandledContacts = nHandledContacts;
}
public Integer getnAbandonedContacts() {
return nAbandonedContacts;
}
public void setnAbandonedContacts(Integer nAbandonedContacts) {
this.nAbandonedContacts = nAbandonedContacts;
}
public Integer getnDequeuedContacts() {
return nDequeuedContacts;
}
public void setnDequeuedContacts(Integer nDequeuedContacts) {
this.nDequeuedContacts = nDequeuedContacts;
}
public Integer getAvgTalkDuration() {
return avgTalkDuration;
}
public void setAvgTalkDuration(Integer avgTalkDuration) {
this.avgTalkDuration = avgTalkDuration;
}
public Integer getLongestTalkDuration() {
return longestTalkDuration;
}
public void setLongestTalkDuration(Integer longestTalkDuration) {
this.longestTalkDuration = longestTalkDuration;
}
public Integer getAvgWaitDuration() {
return avgWaitDuration;
}
public void setAvgWaitDuration(Integer avgWaitDuration) {
this.avgWaitDuration = avgWaitDuration;
}
public Integer getLongestWaitDuration() {
return longestWaitDuration;
}
public void setLongestWaitDuration(Integer longestWaitDuration) {
this.longestWaitDuration = longestWaitDuration;
}
public Integer getLongestCurrentlyWaitingDuration() {
return longestCurrentlyWaitingDuration;
}
public void setLongestCurrentlyWaitingDuration(
Integer longestCurrentlyWaitingDuration) {
this.longestCurrentlyWaitingDuration = longestCurrentlyWaitingDuration;
}
public Integer getnAvailResources() {
return nAvailResources;
}
public void setnAvailResources(Integer nAvailResources) {
this.nAvailResources = nAvailResources;
}
public Integer getnInSessionResources() {
return nInSessionResources;
}
public void setnInSessionResources(Integer nInSessionResources) {
this.nInSessionResources = nInSessionResources;
}
public Integer getnUnavailResources() {
return nUnavailResources;
}
public void setnUnavailResources(Integer nUnavailResources) {
this.nUnavailResources = nUnavailResources;
}
public Integer getnWorkResources() {
return nWorkResources;
}
public void setnWorkResources(Integer nWorkResources) {
this.nWorkResources = nWorkResources;
}
public Integer getnSelectedResources() {
return nSelectedResources;
}
public void setnSelectedResources(Integer nSelectedResources) {
this.nSelectedResources = nSelectedResources;
}
public Integer getnWaitingContacts() {
return nWaitingContacts;
}
public void setnWaitingContacts(Integer nWaitingContacts) {
this.nWaitingContacts = nWaitingContacts;
}
public Integer getnAverageHandlingTimeLowThreshold() {
return nAverageHandlingTimeLowThreshold;
}
public void setnAverageHandlingTimeLowThreshold(
Integer nAverageHandlingTimeLowThreshold) {
this.nAverageHandlingTimeLowThreshold = nAverageHandlingTimeLowThreshold;
}
public Integer getnAverageHandlingTimeHighThreshold() {
return nAverageHandlingTimeHighThreshold;
}
public void setnAverageHandlingTimeHighThreshold(
Integer nAverageHandlingTimeHighThreshold) {
this.nAverageHandlingTimeHighThreshold = nAverageHandlingTimeHighThreshold;
}
public Integer getnAverageWaitingTimeLowThreshold() {
return nAverageWaitingTimeLowThreshold;
}
public void setnAverageWaitingTimeLowThreshold(
Integer nAverageWaitingTimeLowThreshold) {
this.nAverageWaitingTimeLowThreshold = nAverageWaitingTimeLowThreshold;
}
public Integer getnAverageWaitingTimeHighThreshold() {
return nAverageWaitingTimeHighThreshold;
}
public void setnAverageWaitingTimeHighThreshold(
Integer nAverageWaitingTimeHighThreshold) {
this.nAverageWaitingTimeHighThreshold = nAverageWaitingTimeHighThreshold;
}
public Integer getnAbandonedCallsLowThreshold() {
return nAbandonedCallsLowThreshold;
}
public void setnAbandonedCallsLowThreshold(Integer nAbandonedCallsLowThreshold) {
this.nAbandonedCallsLowThreshold = nAbandonedCallsLowThreshold;
}
public Integer getnAbandonedCallsHighThreshold() {
return nAbandonedCallsHighThreshold;
}
public void setnAbandonedCallsHighThreshold(Integer nAbandonedCallsHighThreshold) {
this.nAbandonedCallsHighThreshold = nAbandonedCallsHighThreshold;
}
public Integer getnDequeuedCallsLowThreshold() {
return nDequeuedCallsLowThreshold;
}
public void setnDequeuedCallsLowThreshold(Integer nDequeuedCallsLowThreshold) {
this.nDequeuedCallsLowThreshold = nDequeuedCallsLowThreshold;
}
public Integer getnDequeuedCallsHighThreshold() {
return nDequeuedCallsHighThreshold;
}
public void setnDequeuedCallsHighThreshold(Integer nDequeuedCallsHighThreshold) {
this.nDequeuedCallsHighThreshold = nDequeuedCallsHighThreshold;
}
public Integer getnSLAPercentageLowThreshold() {
return nSLAPercentageLowThreshold;
}
public void setnSLAPercentageLowThreshold(Integer nSLAPercentageLowThreshold) {
this.nSLAPercentageLowThreshold = nSLAPercentageLowThreshold;
}
public Integer getnSLAPercentageHighThreshold() {
return nSLAPercentageHighThreshold;
}
public void setnSLAPercentageHighThreshold(Integer nSLAPercentageHighThreshold) {
this.nSLAPercentageHighThreshold = nSLAPercentageHighThreshold;
}
String id;
Integer esdId;
String esdName;
Integer nResourcesLoggedIn;
Integer nTotalContacts;
Integer nHandledContacts;
Integer nAbandonedContacts;
Integer nDequeuedContacts;
Integer avgTalkDuration;
Integer longestTalkDuration;
Integer avgWaitDuration;
Integer longestWaitDuration;
Integer longestCurrentlyWaitingDuration;
Integer nAvailResources;
Integer nInSessionResources;
Integer nUnavailResources;
Integer nWorkResources;
Integer nSelectedResources;
Integer nWaitingContacts;
Integer nAverageHandlingTimeLowThreshold;
Integer nAverageHandlingTimeHighThreshold;
Integer nAverageWaitingTimeLowThreshold;
Integer nAverageWaitingTimeHighThreshold;
Integer nAbandonedCallsLowThreshold;
Integer nAbandonedCallsHighThreshold;
Integer nDequeuedCallsLowThreshold;
Integer nDequeuedCallsHighThreshold;
Integer nSLAPercentageLowThreshold;
Integer nSLAPercentageHighThreshold;
}
VoiceIAQStatsResponse:
package dk.netdesign.wallboard.dataprovider.uccxrest.domain;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class VoiceIAQStatsResponse extends CiscoStatsResponse {
@XmlElement(name = "VoiceIAQStats")
private VoiceIAQStats voiceIAQStats;
public VoiceIAQStats getVoiceIAQStats() {
return voiceIAQStats;
}
public void setVoiceIAQStats(VoiceIAQStats voiceIAQStats) {
this.voiceIAQStats = voiceIAQStats;
}
}
的JSON看起來是這樣的(這似乎對我正確嗎?)
[{
"id": "Daler Kampagne 2",
"operation": "UPDATE",
"VoiceIAQStats": {
"id": 3,
"esdId": 3,
"esdName": "Daler Kampagne 2",
"nResourcesLoggedIn": 0,
"nTotalContacts": 0,
"nHandledContacts": 0,
"nAbandonedContacts": 0,
"nDequeuedContacts": 0,
"avgTalkDuration": 0,
"longestTalkDuration": 0,
"avgWaitDuration": 0,
"longestWaitDuration": 0,
"longestCurrentlyWaitingDuration": 0,
"nAvailResources": 0,
"nInSessionResources": 0,
"nUnavailResources": 0,
"nWorkResources": 0,
"nSelectedResources": 0,
"nWaitingContacts": 0,
"nAverageHandlingTimeLowThreshold": 0.0,
"nAverageHandlingTimeHighThreshold": 0.0,
"nAverageWaitingTimeLowThreshold": 0.0,
"nAverageWaitingTimeHighThreshold": 0.0,
"nAbandonedCallsLowThreshold": 0,
"nAbandonedCallsHighThreshold": 0,
"nDequeuedCallsLowThreshold": 0,
"nDequeuedCallsHighThreshold": 0,
"nSLAPercentageLowThreshold": 0.0,
"nSLAPercentageHighThreshold": 0.0
}
}, {
"id": "Dialer Kampagne 1",
"operation": "UPDATE",
"VoiceIAQStats": {
"id": 2,
"esdId": 2,
"esdName": "Dialer Kampagne 1",
"nResourcesLoggedIn": 0,
"nTotalContacts": 0,
"nHandledContacts": 0,
"nAbandonedContacts": 0,
"nDequeuedContacts": 0,
"avgTalkDuration": 0,
"longestTalkDuration": 0,
"avgWaitDuration": 0,
"longestWaitDuration": 0,
"longestCurrentlyWaitingDuration": 0,
"nAvailResources": 0,
"nInSessionResources": 0,
"nUnavailResources": 0,
"nWorkResources": 0,
"nSelectedResources": 0,
"nWaitingContacts": 0,
"nAverageHandlingTimeLowThreshold": 0.0,
"nAverageHandlingTimeHighThreshold": 0.0,
"nAverageWaitingTimeLowThreshold": 0.0,
"nAverageWaitingTimeHighThreshold": 0.0,
"nAbandonedCallsLowThreshold": 0,
"nAbandonedCallsHighThreshold": 0,
"nDequeuedCallsLowThreshold": 0,
"nDequeuedCallsHighThreshold": 0,
"nSLAPercentageLowThreshold": 0.0,
"nSLAPercentageHighThreshold": 0.0
}
}, {
"id": "ICD01",
"operation": "UPDATE",
"VoiceIAQStats": {
"id": 1,
"esdId": 1,
"esdName": "ICD01",
"nResourcesLoggedIn": 0,
"nTotalContacts": 0,
"nHandledContacts": 0,
"nAbandonedContacts": 0,
"nDequeuedContacts": 0,
"avgTalkDuration": 0,
"longestTalkDuration": 0,
"avgWaitDuration": 0,
"longestWaitDuration": 0,
"longestCurrentlyWaitingDuration": 0,
"nAvailResources": 0,
"nInSessionResources": 0,
"nUnavailResources": 0,
"nWorkResources": 0,
"nSelectedResources": 0,
"nWaitingContacts": 0,
"nAverageHandlingTimeLowThreshold": 0.0,
"nAverageHandlingTimeHighThreshold": 0.0,
"nAverageWaitingTimeLowThreshold": 0.0,
"nAverageWaitingTimeHighThreshold": 0.0,
"nAbandonedCallsLowThreshold": 0,
"nAbandonedCallsHighThreshold": 0,
"nDequeuedCallsLowThreshold": 0,
"nDequeuedCallsHighThreshold": 0,
"nSLAPercentageLowThreshold": 0.0,
"nSLAPercentageHighThreshold": 0.0
}
}]
編輯:這是我用來調用webservice並返回一個VoiceIAQStatsResponse列表的方法。
public List<VoiceIAQStatsResponse> getVoiceIAQStatsResponse() {
WebTarget resourceWebTarget = getBaseTarget().path("VoiceIAQStats");
Invocation.Builder invocationBuilder = resourceWebTarget
.request(MediaType.APPLICATION_JSON);
javax.ws.rs.core.Response response = invocationBuilder.get();
System.out.println("ÅH ABE" + response.toString());
GenericType<List<VoiceIAQStatsResponse>> type = new GenericType<List<VoiceIAQStatsResponse>>() {
};
logger.debug(response.getStatusInfo().toString());
List<VoiceIAQStatsResponse> list = null;
if (response.getStatusInfo().getFamily().compareTo(Response.Status.Family.SUCCESSFUL) == 0) {
list = response.readEntity(type);
} else {
list = Collections.EMPTY_LIST;
}
return list;
}
我真的很希望有這個問題的經驗的人 - 我似乎無法弄清楚問題所在。
新增的XmlElement在操作字符串(它不是一個名單..)。然而問題似乎是一樣的... – MatiasN