Hi i got a problem with Android JSON Parser in 2.3, all is ok in 4.0>.
I look other topic they are talking about encoding (server) or other stuff server side, but i tried to put "test" in all my JSON field an the problem still persist.
Here is my code :
URL url = new URL(c.getString(R.string.url_ws) + url_ws);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestMethod("POST");
OutputStreamWriter request = new OutputStreamWriter(connection.getOutputStream());
request.write("&test=test");
request.flush();
request.close();
String line;
InputStreamReader isr = new InputStreamReader(connection.getInputStream());
BufferedReader reader = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null){
sb.append(line + "\n");
}
String json = sb.toString().trim();
try {
JSONObject obj = new JSONObject(json);
} catch (JSONException e) {
e.printStackTrace();
Log.d(Tools.TAG+"/debug JSONException", e.toString());
return null;
}
Here is my exception
debug JSONException(4184): org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
i saw double space between "Value" and "of" so i guess the problem is a empty string but i dont get it.
thanks.
EDIT
it was a encode mistake in my JSON,
char a = json.substring(0, 1).charAt(0);
int ascii = (int)a;
Tools.myLog(">"+ascii+"<");
i found 65279 char
SOLUTION
Why is  appearing in my HTML?
encoding UTF-8 without BOM.