0

I have a small problem with my json parser

When i try to parse a string i get this exception:

Unexpected character (<) at position 0

But i dont see where the problem is. This is the code that i made:

JSONParser parser = new JSONParser();
        try {
            Object obj = parser.parse(response);
            System.out.println(obj);

            JSONObject jsonObject = (JSONObject) obj;

            // loop the string
            //id = (String) jsonObject.get("id");
            voornaam = (String) jsonObject.get("voornaam");
            achternaam = (String) jsonObject.get("achternaam");

            _voornaamTxtField.setText(voornaam);
            _achternaamTxtField.setText(achternaam);

        } catch (ParseException pex) {
            JOptionPane.showMessageDialog(null, "ParseException",
                    "Error", JOptionPane.ERROR_MESSAGE);
            System.out.println(pex);
        } catch (NullPointerException npex) {
            JOptionPane.showMessageDialog(null, "NullpointerException",
                    "Error", JOptionPane.ERROR_MESSAGE);
        }

Can someone explain to me what i am doeing to cause the exception

The_Monster
  • 494
  • 2
  • 7
  • 28

1 Answers1

1

Your response string is not a JSON. Most probably it is an XML.
If your response is a response for a http call, you need to specify content type to be "application/json", then may be service will return you a JSON string, if service supports that.

win_wave
  • 1,498
  • 11
  • 9