android - getting \n in encode base64 and so that cannot be converted to JSONObject -
i want encode 3 photos , there no problem, have got problems when want send string php , saving string in mysql using json. logcat below (and happened in first photo):
06-19 14:56:18.141 29570-29586/com.example.indraaaeff.e_fine2 e/json parser﹕ error parsing data org.json.jsonexception: value
then tried print out in debugger , saw string indeed contains \n means <br
here's picture when print string out; think \n in encodedstring1. hope can see \n color blue.
http://postimg.org/image/exonizkb3/
mainactivity2.java
private void encodefoto1(uri urifoto1) { file imagefile1 = new file(urifoto1.getpath()); bitmap bm1 = bitmapfactory.decodefile(imagefile1.getpath()); bytearrayoutputstream baos1 = new bytearrayoutputstream(); bm1.compress(bitmap.compressformat.png, 50, baos1); byte[] byte_arr1 = baos1.tobytearray(); encodedstring1 = base64.encodetostring(byte_arr1, 1); } private void encodefoto2(uri urifoto2) { file imagefile2 = new file(urifoto2.getpath()); bitmap bm2 = bitmapfactory.decodefile(imagefile2.getpath()); bytearrayoutputstream baos2 = new bytearrayoutputstream(); bm2.compress(bitmap.compressformat.png, 50,baos2); byte[] byte_arr2 = baos2.tobytearray(); encodedstring2 = base64.encodetostring(byte_arr2, 2); } private void encodefoto3(uri urifoto3) { file imagefile3 = new file(urifoto3.getpath()); bitmap bm3 = bitmapfactory.decodefile(imagefile3.getpath()); bytearrayoutputstream baos3 = new bytearrayoutputstream(); bm3.compress(bitmap.compressformat.png, 50, baos3); byte[] byte_arr3 = baos3.tobytearray(); encodedstring3 = base64.encodetostring(byte_arr3, 3); } public class kirimdata extends asynctask<string, bundle, string> { @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(mainactivity2.this); pdialog.setmessage("sending data..."); pdialog.setindeterminate(false); pdialog.setcancelable(true); pdialog.show(); } @override protected string doinbackground(string... args) { // todo auto-generated method stub // check success tag int success; try { list<namevaluepair> params = new arraylist<namevaluepair>(2); params.add(new basicnamevaluepair("foto_sim",encodedstring1)); params.add(new basicnamevaluepair("foto_stnk",encodedstring2)); params.add(new basicnamevaluepair("foto_sitaan",encodedstring3)); log.d("request!", "starting"); jsonobject json = parserregister.makehttprequest( send_form_url, "post", params); log.d("url", send_form_url); // full json response log.d("register", json.tostring()); // json success element success = json.getint(tag_success); if (success == 1) { log.d("data sent!", json.tostring()); // pakai method runonuithread jika ingin memulai intent baru runonuithread(new runnable() { @override public void run() { intent = new intent(getapplicationcontext(), menuactivity.class); finish(); startactivity(i); } }); return json.getstring(tag_message); }else{ log.d("sending failed!", json.getstring(tag_message)); return json.getstring(tag_message); } } catch (jsonexception e) { e.printstacktrace(); } return null; } protected void onpostexecute(string file_url) { // dismiss dialog once product deleted pdialog.dismiss(); } } is there solution make right ?
Comments
Post a Comment