1

I'm just recogniced that this code:

try {
        String jsonString =new JSONObject().put("test","Ha/llo").toString();
    } catch (JSONException e) {
        e.printStackTrace();
    }

ouputs the following:

{"test":"Ha\ /llo"}

Does someone knows why it puts an \ for each / ? And how to get the real String? My Strings i want to put are supposed to be big, so I dont want to search for \ to change it to ' '

Edit: .get decodes it again and removes the extra '\' in my case is was an server side problem.

Jones
  • 141
  • 1
  • 9

1 Answers1

1

It is escaping the / character automatically. When a valid JSON client parses your string, it should unescape it, resulting in no issues and the original text. See JSON: why are forward slashes escaped?

jordan
  • 959
  • 7
  • 17