Error: Jsonexception: End of input at Character 0, when sending Android information to a PHP Webservice

Asked

Viewed 1,443 times

0

I’m sending information from Android to a PHP Webservice via lib Volley.
Everything works perfectly, except with special characters.

Map<String, String> params = new HashMap<String, String>();
params.put("nome", "áàâãõóòúç");

If the name equals - nome = Maria das Graças for example, he gives me that mistake:

Error output:

W/System.err: org.json.Jsonexception: End of input at Character 0 of
W/System.err: at org.json.JSONTokener.syntaxError(JSONTokener.java:450) > W/System.err: at org.json.JSONTokener.nextValue(JSONTokener.java:97)
W/System.err: at org.json.Jsonobject. (Jsonobject.java:155)
W/System.err: at org.json.Jsonobject.(Jsonobject.java:172) W/System.err: at Jsonobjectrequest.parseNetworkResponse(Customjsonobjectrequest.java:58)
W/System.err: at com.android.Volley.NetworkDispatcher.run(Networkdispatcher.java:125)
E/Volley: [8220] Networkdispatcher.run: Unhandled Exception
java.lang.Nullpointerexception
java.lang.Nullpointerexception at com.android.Volley.NetworkDispatcher.run(Networkdispatcher.java:130)

In PHP I had the same problem at the beginning and solved using the function utf8_encoder.

1 answer

0


You need to encode before sending any string with special characters through your JSON.

Try using the class URLEncoder, something like that:

String nome = URLEncoder.encode("áàâãõóòúç", "utf-8");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.