【发布时间】:2012-04-27 09:37:52
【问题描述】:
我遇到了数据格式问题。我有一个简单的 JaxB 类
@XmlRootElement(name="")
public class MyProgressResponse {
private int weight;
private long date;
/**
* Weight is treated as a Y Axis.
* @return
*/
@XmlElement(name="y")
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
/**
* This is a UTC format of a time.
* value is a number of milliseconds between a specified date and midnight January 1 1970
* This is also treated as a X-Axis
* @return
*/
@XmlElement(name="x")
public long getDate() {
return date;
}
public void setDate(long date) {
this.date = date;
}
}
我想要填充返回数据的 REST 服务。像这样
@GET
@Path("/my")
@Produces(MediaType.APPLICATION_JSON)
public MyProgressResponse[] getProgressResponse(){
// Get the data from DB
// Here the getDate will give me List<MyProgressResponse>
return getData().toArray(new MyProgressResponse[0]);
}
现在我收到的 JSON 就像
[
{
{
"x": 1335499200000,
"y": 85
}
},
{
{
"x": 1334894400000,
"y": 84
}
},
....
]
但我的要求是获得没有一个额外块{ }。
[
{
"x": 1335499200000,
"y": 85
},
{
"x": 1334894400000,
"y": 84
},
....
]
我想在 HighChart 中使用它。我可以在收到数据后在 JS 中格式化数据,但它会花费额外的时间,我不希望这样。
谁能帮我格式化数据
谢谢,
塔尔哈·艾哈迈德·汗
【问题讨论】:
-
如果您将输出作为 XML 而不是 JSON 返回,它的外观如何?
-
你能发布你的
MyProgressResponse类吗?你提供的 JSON 输出真的很奇怪,对我来说它看起来与MyProgressResponse类继承有关。
标签: java javascript rest jakarta-ee jaxb