Write HTML string in JSON

前端 未结 11 1452
小蘑菇
小蘑菇 2020-12-09 08:25

Is it possible to write an HTML string inside JSON?

Which I want to write like below in my JSON file:

[
    {
        \"id\": \"services.html\",
             


        
11条回答
  •  没有蜡笔的小新
    2020-12-09 08:57

    Just encode html using Base64 algorithm before adding html to the JSON and decode html using Base64 when you read.

    byte[] utf8 = htmlMessage.getBytes("UTF8");
    htmlMessage= new String(new Base64().encode(utf8));
    
    
    byte[] dec = new Base64().decode(htmlMessage.getBytes());
    htmlMessage = new String(dec , "UTF8");
    

提交回复
热议问题