I need to send my data using json and send a message using byte [] in my json. Now I can get the bitmap to convert to bytearray using the following line of codes:
selectedImageBitmap.compress(Bitmap.CompressFormat.JPEG, 100,stream); byte[] byteArray = stream.toByteArray();
But I can not put this byte array in Json. I use the Json object for Android by default 2.1. When I try to convert byte [] to JSONArray, it gives me an exception in memory.
JSONArray jsonArray = new JSONArray(); for(int i=0;i<byteArray.length;i++) { jsonArray.put(byteArray[i]); }
When I try to put an object directly in JsonObject, it returns a weird sixth line in toString () (possibly the memory location of the objects).
Can someone please help me with this. Is there a standard way to put byte [] in json?
PS: I first tried using base64. But this often leads to memory exceptions, since the images I have to send and receive are large and therefore base64 is also big!
source share