如下述数据,在java中如何转成json格式?

[
[
[
{
"id": 0,
"cont": "我",
"pos": "r",
"ne": "O"
},
{
"id": 1,
"cont": "想",
"pos": "v",
"ne": "O"
},
{
"id": 2,
"cont": "吃",
"pos": "v",
"ne": "O"
},
{
"id": 3,
"cont": "橘子",
"pos": "n",
"ne": "O"
},
{
"id": 4,
"cont": "。",
"pos": "wp",
"ne": "O"
}
]
]
]
最新回答
爷傲灬奈我何

2024-11-02 09:58:40

public static void main(String[] args) {
    //初始化一个List
    List<Province> list = new ArrayList<>();
    //声明范型的实体1
    Province c1 = new Province();
    c1.setProvinceName("南京");
    c1.setProvinceSort("1");
    //声明范型的实体2
    Province c2 = new Province();
    c2.setProvinceName("北京");
    c2.setProvinceSort("2");
    //加入List中
    list.add(c1);
    list.add(c2);
    //打印JSON格式的串
    System.out.println(JSON.toJSON(list).toString());
}
[{"provinceName":"南京","provinceSort":"1"},{"provinceName":"北京","provinceSort":"2"}]
梦幻樱雪

2024-11-02 06:06:39

如果这个是个字符串就先把前后两个[]去掉 转jsonArray.