jsonjava-melwuitlwuit-textarea

I have a JSON Service that returns results with "\n" when InputStreamReader reads the result "\" is gone


I have a JSON Service that returns results with "\n" when InputStreamReader reads the result the "\" is gone and leaving the "n" in the String.

I'm having trouble converting the "\n" to next line to be displayed in a TextArea.

For example:

Service Result: Hello\nWorld
PassThrough InputStreamReader: HellonWorld
TextArea Output: HellonWorld

I need it to be:

Service Result: Hello\nWorld
PassThrough InputStreamReader: Hello
World
TextArea Output: Hello
World

Please help me on how to result this problem.

I'm using LWUIT and is developing for a J2ME device.


Solution

  • This is not the best way to do this but here it is:

    Add the following lines to the JSONParser.java

    else if (c == 'n') {
        c = '\n';
    }
    

    below

    c = (char) i.read();
    if (c == 'u') {
        String unicode = "" + ((char) i.read()) + ((char) i.read()) + ((char) i.read()) + ((char) i.read());
        try {
            c = (char) Integer.parseInt(unicode, 16);
        } catch (NumberFormatException err) {
            // problem in parsing the u notation!
            err.printStackTrace();
            System.out.println("Error in parsing \\u" + unicode);
        }
    }