我想发送json,里面有另一个json对象,如下所示
{
"key1": "value1",
"key2": "valu2",
"content": {
"nestedkey1": "nestedValue1",
"nestedkey2": "nestedValue2"
}}
里面的对象没有任何java表示,只有json格式的字符串。如何才能正确转换它?
我的方法不正确,我总是收到嵌套json的空字符串。我对这个嵌套对象使用了Map,但再次为空map。
public class Instance {
private String key1;
private int key2;
private String content;
public String getKey1 {
return key1;
}
public void setKey1(String key1) {
this.key1 = key1;
}
public BigDecimal getKey2() {
return key2;
}
public void setKey2(BigDecimal key2) {
this.key2 = key2;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}发布于 2011-04-23 00:03:59
JSON序列化是如何完成的?如果您没有使用Jackson,那么您应该使用它。
Jackson可以获取Map并将其转换为JSON,就像您想要的那样,而不需要任何额外的配置。另一方面,如果您使用Jersey JSON插件,则必须编写Map的子类,并为其添加JAXB注释-这有点麻烦。
https://stackoverflow.com/questions/5755611
复制相似问题