Zerok Zerok - 11 months ago 62
Java Question

SyntaxError: JSON.parse: expected property name or '}'

I'm using the following code, trying to send the JSON line to the client, for testing purposes:

String json = "{'nombre':'Donell', 'dni':'351351P'}";
PrintWriter out = response.getWriter();
JSONObject jsonObj = (JSONObject) JSONValue.parse(json);

I'm using the library json-simple, but this isn't working. When I access to "/Prueba", which is my test servlet, I receive a package with 200 code type "json", but without data:

enter image description here

What's wrong here? Thank you!

edit: When trying to just write the json, I see it, but with an error:

enter image description here


Since you already have the json string in variable json simply print this string to the response:


Also the json string should use double quotes

"{\"nombre\":\"Donell\", \"dni\":\"351351P\"}"

(When you parsed the old invalid string, you got a null JSONObject and therefore you saw a null in the response, when printing the object).