我想使用 JQuery 将一组位置发送到 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)