fastjson toString 特殊字符转义问题

pvabu6sv  于 2021-11-27  发布在  Java
关注(0)|答案(4)|浏览(440)

JSONObject j =new JSONObject();
j.put("content", "内容中有\t没有被转义");
System.out.println(j);

tpgth1q7

tpgth1q71#

个人觉得这个地方也没有必要转义,也不会去转义

f5emj3cl

f5emj3cl2#

import com.alibaba.fastjson.JSONObject;

public class Demo {
    public static void main(String[] args) {
        JSONObject json = new JSONObject();
        json.put("key", "content\tvalue");
        System.out.println(json.get("key"));
        // result:content	value
    }
}

刚刚试了一下可以啊,\t转成制表符了

tvz2xvvm

tvz2xvvm3#

\t should not be converted to a tab. Tabs are not allowed inside strings.

The JSON Data Interchange Syntax says: Insignificant whitespace is allowed before or after any token. Whitespace is any sequence of one or more of the following code points: character tabulation (U+0009), line feed (U+000A), carriage return (U+000D), and space (U+0020). Whitespace is not allowed within any token, except that space is allowed in strings.

vawmfj5a

vawmfj5a4#

This issue has been fixed and can be closed. It's escaping tabs correctly
Tested both \t and \u0009 on version 1.2.75

相关问题