2016-11-25 20 views
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 
} 
}] 

EDIT:これは私がWebサービスを呼び出すと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; 
} 

私は本当にこの問題での経験を持った人のために期待していた - 私はこの問題を把握するように見えることはできません。

答えて

1

この場合、エラーメッセージは非常に正確です。あなたが持っているのは、JSONオブジェクトではなくJSON配列です。あなたはいつでも簡単にそれらを変換することができます:

有効なJSONです。 (そのないリスト...)の操作列に

@XmlRootElement 
@XmlAccessorType(XmlAccessType.FIELD) 
public class VoiceIAQStatsResponses { 

@XmlElement(name = "operations") 
private List<VoiceIAQStatsResponse> operations; 

... 

} 
+0

追加のXmlElement:

その後、あなたは他のトップレベルの要素が必要になります。しかし、問題は同じように見える... – MatiasN

関連する問題