How to encode JSON embedded within JSON

前端 未结 1 713
渐次进展
渐次进展 2021-01-17 09:52

I have a JSON string and one of the fields is a text field. This text field can contain text that a user enters in the UI and if the text they enter is JSON text, perhaps to

相关标签:
1条回答
  • 2021-01-17 10:16

    I'm doing something similar, just with XML instead of JSON: On receiving malformed or otherwise non-processable data the server returns an error-structure containing some information and the original data. To prevent the client from parsing the corrupt data again it's base64 encoded on the server.

    So instead of sending

    {
      title : "My sample code",
      payload : "{ \"foo\" : \"bar\" }"
    }
    

    consider sending

    {
      title : "My encoded sample code",
      payload : "eyAiZm9vIiA6ICJiYXIiIH0="
    }
    
    0 讨论(0)
提交回复
热议问题