Error: JSONException: End of input at character 0, when sending information from Android to a PHP WebService

0

I'm sending information from Android to a PHP WebService through the Volley lib. Everything works perfectly except with special characters.

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

If the name is equal to - nome = Maria das Graças for example, it gives me this error:

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 first and solved using the utf8_encoder function.

    
asked by anonymous 25.01.2016 / 07:45

1 answer

0

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

Try using the class URLEncoder , something like this:

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