var httpc = new XMLHttpRequest(); // simplified for clarity
httpc.open("POST", url, true); // sending as POST
httpc.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
httpc.onreadystatechange = function() { // Call a function when the
// state changes.
if (httpc.readyState == 4 && httpc.status == 200) {
//MY JSON RESPONSE
alert(JSON.stringify(httpc.responseText));
}
}
httpc.send(params);
The above code is working fine in android 4.0 and response is getting in valid JSON format..
but when i run the same code in android 2.3 i’m getting response in unknown format and my url and params are same for both android versions.
in 2.3 my response is .
�I�%&/m�{J�J��t��$ؐ@�����iG#)�*��eVe]f@�흼��{���{��;�N’���?\fdl��J�ɞ!���?~|?”��?�YQ~�裏F�������n���/����ț&����2���u�~����)`�U��TH��2Ϛ<}S_��Y��z:%�����,�o�e��tv��X��E��{?v��U��V�j�B�s�FU�~�p�Զ�ɢ�i�2[^�i�S��W���_���’������
in 4.0 my response is
[{“email”:””,”password”:””,”user_id”:””,”store_id”:””,”message”:”Alert!, Wrong Email or Password Please Try Again.”,”success”:”0″,”nick_name”:””,”magazine_genre_id”:””,”magazine_genre_name”:””,”newspaper_genre_id”:””,”newspaper_genre_name”:””,”old_password”:””,”new_password”:””,”mode”:””,”languagecode”:””,”URL”:””}] at file:///android_asset/www/project.js:717
Logcat exception: SyntaxError: Parse error at undefined:1
Have you tried setting the
responseTypetojson. I have only used it from jquery. If you have any doubt check this XMLHttpRequestAnswer
There are some alternatives provided in this SO post JSON Parsing works on Android 4.0 but not on Android < 4.0