Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在其他JSONObject中处理JSONObject_Java_Json_Rest_Jersey - Fatal编程技术网

Java 在其他JSONObject中处理JSONObject

Java 在其他JSONObject中处理JSONObject,java,json,rest,jersey,Java,Json,Rest,Jersey,我想发送json,其中包含另一个json对象,如下所示 { "key1": "value1", "key2": "valu2", "content": { "nestedkey1": "nestedValue1", "nestedkey2": "nestedValue2" } } 对象内部没有任何java表示,只有json格式的字符串。如何正确转换 我的方法不正确,我总是收到嵌套json的空字符串。我对这个嵌套对象使

我想发送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;
}

JSON序列化是如何完成的?如果你没有使用,那么你应该使用

Jackson可以获取一个映射,并按照您的意愿将其转换为JSON,而无需任何其他配置。另一方面,如果您使用的是Jersey JSON插件,那么您必须编写Map的一个子类,并向其添加JAXB注释——这有点麻烦