Java escape JSON String?

前端 未结 10 635
再見小時候
再見小時候 2020-12-08 11:27

I have the following JSON string that i am sending to a NodeJS server:

String string = \"{\\\"id\\\":\\\"\" + userID + \"\\\",\\\"type\\\":\\\"\" + methoden          


        
10条回答
  •  温柔的废话
    2020-12-08 12:00

    org.json.simple.JSONObject.escape() escapes quotes,, /, \r, \n, \b, \f, \t and other control characters.

    import org.json.simple.JSONValue;
    JSONValue.escape("test string");
    
    • json-simple home
    • document

    Add pom.xml when using maven

    
        com.googlecode.json-simple
        json-simple
        test
    
    

提交回复
热议问题