storing xml inside json object

前端 未结 3 457
不知归路
不知归路 2021-01-04 00:27

I need to store complete xml document as part of json object. when i receive the request and try to create json object from json string like below -

{\"conte         


        
相关标签:
3条回答
  • 2021-01-04 00:35

    Don't want to remove the line breaks from the xml but made change in json java class to not throw unterminated string exception for NL, CR. thanks Explosion Pills.

    0 讨论(0)
  • 2021-01-04 00:37

    You can encode and decode xml string like

    {
      "content": {
        "name": "xyz",
        "details": "PD94bWwgdmVyc2lvbj1cIjEuMFwiIGVuY29kaW5nPVwiVVRGLThcIj8+CiA8bnMwOlJlcG9ydCB4bWxuczpuczA9XCJodHRwOi8vd3d3LmtoaXNrby5jb20vdHJpVHlwZXNcIj4KICA8U3RhY2tUcmFjZT5Kb2ItODAwNCBFcnJvciBpbiBbeHh4eHh4eHh4eF0KICAgICAgT3V0cHV0IGRhdGEgaW52YWxpZCYjeEQ7CiAgYXQgY29tLnh5ei50c3QuYShVbmtub3duIFNvdXJjZSkmI3hEOwogICAgICBjYXVzZWQgYnk6IGphdmEubGFuZy5OdWxsUG9pbnRlckV4Y2VwdGlvbiYjeEQ7CiAgIDwvU3RhY2tUcmFjZT4KICAgPE1zZz5PdXRwdXQgZGF0YSBpbnZhbGlkPC9Nc2c+CiAgPC9uczA6UmVwb3J0Pg==",
        "encoding": "base64"
      }
    }
    
    0 讨论(0)
  • 2021-01-04 01:00

    Just I've changed \" to ' and remove line breaks like @Explosion Pills says

    {"content":{
        "name" : "xyz",
        "details":"<?xml version='1.0' encoding='UTF-8'?>
         <ns0:Report xmlns:ns0='http://www.khisko.com/triTypes'>
          <StackTrace>Job-8004 Error in [xxxxxxxxxx]
              Output data invalid&#xD;
          at com.xyz.tst.a(Unknown Source)&#xD;
              caused by: java.lang.NullPointerException&#xD;
           </StackTrace>
           <Msg>Output data invalid</Msg>
          </ns0:Report>"
         }}
    
    0 讨论(0)
提交回复
热议问题