Reputation: 45
I'm setting up a new server and android, and want to send base64(image) from android to server. I use JSON for data format between android and server, so I have to put my base64 into that JSON, but the server cannot decode my base64 because there are a symbol like "\n,+," and many more. I also try using Notepad for replace "\n" but still the server wont decode it..
note: if I use Postman the server work properly
JSONArray data = new JSONArray();
for (int i = 0; i < listImage.size(); i++) {
//listImage.get(i).setBase64(map.get(listImage.get(i).getId()));
jsonObject = new JSONObject();
jsonObject.put("id",listImage.get(i).getId());
jsonObject.put("base64",map.get(listImage.get(i).getId()));
data.put(jsonObject);
}
jsonObject = new JSONObject();
jsonObject.put("image",data);
Upvotes: 0
Views: 2530
Reputation: 45
thank you for your answer guys...I have found my own solution, I need to replace "\n" and "\" with "" from base64 in server side
Upvotes: 0
Reputation: 483
JSONObject has toString() method that return json object data into String format. You can also look at UTF encoding to encode special character, to make http request without conflicting of special character in URL.
jsonObject = new JSONObject();
jsonObject.put("image",data);
jsonObject.toString();
Upvotes: 1
Reputation: 771
Easiest way to convert jason object to a String
JSONObject json = new JSONObject();
json.toString();
Upvotes: 1