JSON,JAXB,格式问题
JSON, JAXB, Formatting issues
我在数据格式问题上遇到了麻烦。我有一个简单的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 格式化数据,但它会得到额外的时间,我不想这样。
任何人都可以帮助我格式化数据吗
谢谢
塔哈·艾哈迈德·汗
将方法的返回类型更改为 ArrayList:
@GET @Path("/my")
@Produces(MediaType.APPLICATION_JSON)
public ArrayList<MyProgressResponse> getProgressResponse(){
// Get the data from DB
// Here the getDate will give me List<MyProgressResponse>
ArrayList<MyProgressResponse> response=(ArrayList<MyProgressResponse>) getData();
return response;
}
还要使你的 Bean 类实现可序列化。
相关文章:
- 格式问题:下拉复选框
- JSON 格式问题
- Ckeditor出现格式错误的html问题
- 响应出现JSON格式问题
- 反应格式问题
- 使用时刻验证日期时出现问题.js按格式
- 日期列中的剑道网格格式时间问题
- Chrome 扩展程序 - 将 CSV 文件上传到 Dropbox 格式问题
- 原生质日期选择器:不同日期时间格式的问题
- Angularjs - javascript 日期格式问题
- 使用 momentjs 和引导日历时的日期格式问题
- JSON,JAXB,格式问题
- WordPress格式问题 - 存档和间距
- 复制时 JQuery 日期选取器日期格式问题
- D3 堆栈区域数据格式问题
- 时间格式的 JavaScript 正则表达式验证问题
- 姜戈模板 - 日期格式问题
- d3包布局中的Json格式问题
- Javascript Web API JSON解析格式问题
- 点击时设置隐藏嵌套列表格式有问题