0

I'm trying to deal with JSON and I found /u200b (Zero width space) right before double values. I cant pares it right now, even setting the filed type to String. Here I can easily remove it, but how to deal with downloading content from a server?

  String testJson = "{" +
            "    \"name\": \"Aarhus\"," +
            "    \"latitude\": \u200B56.3," +
            "    \"longitude\": \u200B10.619," 
            " }";
Serafins
  • 1,237
  • 1
  • 17
  • 36
  • You won't be able to parse a string that doesn't have quotes around it, and numbers are not supposed to have any characters besides digits, minus etc. - so what you have here is not valid JSON. – RealSkeptic May 12 '16 at 18:16
  • Yes, I know. But it is like that on a server and I have to deal with it as it is. I'm trying to download it as a String and later on remove this values. – Serafins May 12 '16 at 18:18

2 Answers2

4

Use the following replacement if you already have your data in a string.

testJson =testJson.replaceAll("\u200B", "");

If you need to load data from url first, then some clever ways are discussed here: Read url to string in few lines of java code

Community
  • 1
  • 1
Aleksei Egorov
  • 801
  • 9
  • 16
0

You can try to use Jackson, it has many options such as FAIL_ON_UNKNOWN_PROPERTIES and ACCEPT_SINGLE_VALUE_AS_ARRAY. It might help