1

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.

bharath
  • 14,283
  • 16
  • 57
  • 95
bernardnapoleon
  • 373
  • 1
  • 3
  • 13

2 Answers2

1

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);
    }
}
bernardnapoleon
  • 373
  • 1
  • 3
  • 13
0

Can you paste the exact JSON string returned. If the data is within double quotes " then it shouldn't be modified at all with the exception of decoding the \u notations.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • Solved the problem already. Yeah, that should be the case, but from the service I'm accessing, I need to handle it. Thank you very much anyways! it's something like this anyways: "description":"Lorem ipsum dolor sit amet,\n consectetur adipiscing elit." – bernardnapoleon Nov 25 '11 at 04:10