【发布时间】:2014-05-12 00:49:25
【问题描述】:
我正在返回一个带有 Object FLineType 的向量
返回方法看起来像
@GET
@Path("/linetypes")
@Produces(MediaType.APPLICATION_JSON)
public Vector<FLineType> getLineTypes(){
db = Database.getInstance();
return db.getLineTypes();
}
FLineType 看起来像
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class FLineType {
private int id;
private String bez;
public FLineType(){}
public FLineType(int id, String bez) {
super();
this.id = id;
this.bez = bez;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getBez() {
return bez;
}
public void setBez(String bez) {
this.bez = bez;
}
}
我收到的数据看起来像
{"fLineType":[{"bez":"Linie 1","id":"1"},{"bez":"Linie 2","id":"2"},{"bez":"Linie 3","id":"3"},{"bez":"Powerplay 1","id":"4"},{"bez":"Powerplay 2","id":"5"},{"bez":"Unterzahl 1","id":"6"},{"bez":"Unterzahl 2","id":"7"}]}
但我只想要 [] 括号中的 JSON 数组数据。没有对象名称。
因为我收到时会收到JSONException that the Data must start with [。
我将 jersey 1.18 用于 REST 服务器。
谁能帮帮我?
【问题讨论】:
-
为什么是
Vector?为什么不是简单的List甚至是Collection? -
@fge: 我得到了与
List或Array相同的结果 -
然后使用
List。Vector已过时。 -
我得到了同样的错误结果。
-
我知道这不能解决你的问题,但这是 2014 年,你不应该使用
Vector-- 无论如何,我怀疑问题出在@XmlRootElement;你真的需要吗?
标签: java json rest jersey getjson