我想使用JQuery將位置數組發送到REST服務。如何使用POST將數組發送到REST服務(澤西島)
我的代碼
var locations = new Array();
var loc = new Location();
loc.alt = 0;
loc.lat = 0;
loc.long = 0;
loc.time = 1;
locations.push(loc);
var json_data = {value : JSON.stringify(locations)};
console.log(json_data);
$.ajax({type: 'POST',
url: rootURL + '/Location/123',
crossDomain: true,
dataType: "json", // data type of response
contentType: "application/json; charset=utf-8",
data: json_data,
success: function(data, textStatus, jqXHR) {
console.log('testAddLocations erfolgreich');
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('testAddLocations Fehler');
}
});
REST的服務
@POST
@Produces({ MediaType.APPLICATION_JSON })
@Path("{tripID}")
public Response addLocations(@PathParam("tripID") final String tripID, Location[] value) {
,但我得到一個HTTP-500錯誤。在服務器上:
SCHWERWIEGEND: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
JsonFormatException{text=v, line=1, column=1}
at com.sun.jersey.json.impl.reader.JsonLexer.yylex(JsonLexer.java:662)
at com.sun.jersey.json.impl.reader.JsonXmlStreamReader.nextToken(JsonXmlStreamReader.java:162)