Search code examples
javaencodingapache-axisencode

Any other encode like base64?


Are there some encode algorithm like base64?

I have some String that include HTML tag, I should encode them so that run in my JSON Web service. the html String like

<p>test</p>\r\n\r\n

seems not proper for json

I'm try the Java base64 encode my String, it's run. But when I deploy at my machine (axis 2 web service), the encoded String changed... (it's run well at eclipse, both of them use axis 2)

I'm trying to debug, but have a little of success.

Are there some encode algorithms like base64?

Thanks!


Solution

  • JSON is JavaScript, so you probably want to escape them appropriately for JavaScript. JavaScript escapes characters with \nn where 'nn' is the hexadecimal value of the character.

    In your example, the encoding would be

    \60p\62test\60\47p\62\13\10\13\10