jaxb+json,给一段json格式,jaxb怎么写?因为刚学这个,不太会,高手来看看。

跳蚤图 2013-01-17 06:12:42

如果格式是
{
"a":{
"a_id": "a_id",
"a_type": "a_type",
"o_type": "o_type",
"e_id": "e_id"
}
}
我知道
@XmlRootElement(name = "a")
public class Info {

protected String a_type;
protected String o_type;
protected String e_id;
protected String a_id;

@XmlAttribute(required = true)

public String geta_id() {
return a_id;
}

public void seta_id(String a_id) {
this.a_id= a_id;
}
@XmlAttribute(required = true)

public String geta_type() {
return a_type;
}

public void seta_type(String a_type) {
this.a_type= a_type;
}
@XmlAttribute(required = true)

public String geto_type() {
return o_type;
}

public void seto_type(String o_type) {
this.o_type= o_type;
}
@XmlAttribute(required = true)

public String gete_id() {
return e_id;
}

public void sete_id(String e_id) {
this.e_id= e_id;
}

}


下面的json格式怎么用jaxb来表示啊:

{
"a":{
"a_id": "a_id",
"a_type": "a_type",
"o_type": "o_type",
"e_id": "e_id"
},
"s": "Ated",
"r_time": "r_time"
}

因为刚学这个,不太会,高手来看看。
...全文
242 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
跳蚤图 2013-01-22
  • 打赏
  • 举报
回复
引用 2 楼 wy100304441 的回复:
层次也是 class XXX{ private Info a; //a里面有a_id,a_type 等。 private String s; private r_time; }
我主要迷惑的是 上面那段json数据,好像没有根节点,做java类的时候不知道@XmlRootElement怎么赋值???
跳蚤图 2013-01-22
  • 打赏
  • 举报
回复
引用 1 楼 wy100304441 的回复:
jaxb 是针对 xml 的操作。你把 json 需要去用 jaxb 来表示 是来弄啥。?
我看帮助文档,jaxb也能操作json格式啊? http://docs.jboss.org/resteasy/docs/2.3.5.Final/userguide/html_single/index.html#JAXB_+_JSON_provider
  • 打赏
  • 举报
回复
层次也是 class XXX{ private Info a; //a里面有a_id,a_type 等。 private String s; private r_time; }
  • 打赏
  • 举报
回复
jaxb 是针对 xml 的操作。你把 json 需要去用 jaxb 来表示 是来弄啥。?

25,980

社区成员

发帖
与我相关
我的任务
社区描述
高性能WEB开发
社区管理员
  • 高性能WEB开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧