对String对象进行JSON序列化

对对象进行JSON序列化,会得到类似key:value的形式。
但是如果对一个String字符串进行JSON序列化会得到什么?
测试下:

public class TestMain2 {
    public static void main(String args[]){
        String s = "a";
        System.out.println(JSON.toJSONString(s));
        System.out.println(s);
    }
}

输出:序列化后的结果被双引号包括。

而该双引号包含的字符串也的确是JSON格式,可以被JSON工具识别。

posted @ 2019-11-15 13:01  不无聊  阅读(1590)  评论(0编辑  收藏  举报