5

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)

John
  • 159
  • 1
  • 5
  • 12

2 Answers2

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)

Community
  • 1
  • 1
Knickedi
  • 8,742
  • 3
  • 43
  • 45
  • 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.

Community
  • 1
  • 1
Witek
  • 6,160
  • 7
  • 43
  • 63