0

I have been getting a error parse my JSON file

Input

{"continent":"South America","recentJobRank":717,"latitude":"-34.6037232","lastSeenDate":"2012-11-23","start":"Inmediato","contactPerson":"Alejandra Perez","lastJobRank":2,"title":"Encimador","salary":"Convenio","jobtype":"Tiempo Completo","url":"http://www.computrabajo.com.ar/bt-ofrd-deglay-7148.htm","postedDate":"2012-11-21","duration":"Indeterminada","firstSeenDate":"2012-11-23","phoneNumber":"011 4648-0226 RRHH","faxNumber":"011 4648-0226","location":"Buenos Aires, Argentina","company":"Deglay S.R.L.","id":"34076","department":"Buenos Aires","category":"others","applications":"Por e-mail o comunicandose a los telefonos","longitude":"-58.3815931"}

Below is the exception i have recieved

Exception

Unexpected character (J) at position 457. Exception Caught in addfields at org.json.simple.parser.Yylex.yylex(Yylex.java:610) at org.json.simple.parser.JSONParser.nextToken(JSONParser.java:269)

I have tried checking my json on a Validator.It seems fine. Any obvious mistake that i am making ?

1 Answers1

0

The JSON is definitely correct, since JSON.parse() accepts it. I can't really reproduce your error with the json-simple library. I downloaded every version available here, copy-pasted your JSON string and passed it to JSONParser.parse() and got no error in any version.

Here is my setup:

public static void main(String[] args)  {
    try {
      StringReader x = new StringReader("{\"continent\":\"South America\",\"recentJobRank\":717,\"latitude\":\"-34.6037232\",\"lastSeenDate\":\"2012-11-23\",\"start\":\"Inmediato\",\"contactPerson\":\"Alejandra Perez\",\"lastJobRank\":2,\"title\":\"Encimador\",\"salary\":\"Convenio\",\"jobtype\":\"Tiempo Completo\",\"url\":\"http://www.computrabajo.com.ar/bt-ofrd-deglay-7148.htm\",\"postedDate\":\"2012-11-21\",\"duration\":\"Indeterminada\",\"firstSeenDate\":\"2012-11-23\",\"phoneNumber\":\"011 4648-0226 RRHH\",\"faxNumber\":\"011 4648-0226\",\"location\":\"Buenos Aires, Argentina\",\"company\":\"Deglay S.R.L.\",\"id\":\"34076\",\"department\":\"Buenos Aires\",\"category\":\"others\",\"applications\":\"Por e-mail o comunicandose a los telefonos\",\"longitude\":\"-58.3815931\"}");
      new JSONParser().parse(x);
    } catch(Exception e) {
       System.out.println("Error: " + e);
    }

    System.out.println("Success");    
}

So I assume neither your JSON, nor the library is at fault here. My guess would be the encoding of your JSON string, since the error message says

Unexpected character (J) at position 457.

and there is no J anywhere close to this position. So either the JSON you receive is encoded in a way, which SimpleJSON can't correctly parse, or the data doesn't get transmitted completely/correctly.

Maybe it could help to tell, where you got the JSON from and how you pass it into JSONParser.parse().

lSoleyl
  • 309
  • 1
  • 7