With my android app, I want to upload some text and image in a server. My problem is how to convert an image(from my phone) to a json object or json array. (I use 1.6 android sdk for my app)
Asked
Active
Viewed 9,191 times
2 Answers
3
Usually you encode binary data as Base64. This allows to represent any kind of byte data as text. Consider the fact that the image is expanding by the ratio 4:3.
Edit: How to convert a image into Base64 string? (here you'll find a Base64 helper for API less than 8)
-
Yes, exactly. That's the answer you're searching for. You can encode any byte array like that. You have to consider whether you want to expand binary data to a text representation. – Knickedi Nov 29 '11 at 15:58
2
First you should be sure you want to do this. Perhaps there is a way to store the image as a plain file (or attachment?) on your server.
Otherwise get the byte data from the image. Then convert byte after byte into a huge string. Then the string could be stored as a property in your JSON object. You could use Base64 encoding too.