相关疑难解决方法(0)

使用Jackson将Java对象转换为JSON

我希望我的JSON看起来像这样:

{
    "information": [{
        "timestamp": "xxxx",
        "feature": "xxxx",
        "ean": 1234,
        "data": "xxxx"
    }, {
        "timestamp": "yyy",
        "feature": "yyy",
        "ean": 12345,
        "data": "yyy"
    }]
}
Run Code Online (Sandbox Code Playgroud)

代码到目前为止:

import java.util.List;

public class ValueData {

    private List<ValueItems> information;

    public ValueData(){

    }

    public List<ValueItems> getInformation() {
        return information;
    }

    public void setInformation(List<ValueItems> information) {
        this.information = information;
    }

    @Override
    public String toString() {
        return String.format("{information:%s}", information);
    }

}
Run Code Online (Sandbox Code Playgroud)

和

public class ValueItems {

    private String timestamp;
    private String feature;
    private int ean;
    private String data; …
Run Code Online (Sandbox Code Playgroud)

java json object jackson

148
推荐指数
6
解决办法
36万
查看次数

如何在JsonNode中创建插入新节点?

我有一个新创建的JsonNode

JsonNode jNode = new ObjectCodec().createObjectNode();
Run Code Online (Sandbox Code Playgroud)

使用此节点,我如何在其中添加键值对,以便我可以使用新值构造此新节点?我在http://www.cowtowncoder.com/blog/archives/2011/08/entry_460.html中提到的有关使用的内容

jNode.with("newNode").put("key1","value1");
Run Code Online (Sandbox Code Playgroud)

但是看看Jackson的JsonNode(v1.8)的API并没有显示任何方法.

json jackson

54
推荐指数
2
解决办法
11万
查看次数

标签 统计

jackson ×2

json ×2

java ×1

object ×1