Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert image to JSON

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)

like image 686
John Avatar asked Nov 29 '11 15:11

John


People also ask

Can image be converted to JSON?

An image is of the type "binary" which is none of those. So you can't directly insert an image into JSON. What you can do is convert the image to a textual representation which can then be used as a normal string. The most common way to achieve that is with what's called base64.

Can I convert PNG to JSON?

Yes, you can use PNG to JSON Encoder on any operating system that has a web browser.

Can you add images to JSON?

Simple JSON If what you want to do is simply to add the image in the platform, you just need to list all the images location in the JSON, as seen in the example below. Each entry in the images list corresponds to an image and contains the following fields: location : image URL.


2 Answers

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)

like image 112
Knickedi Avatar answered Sep 22 '22 14:09

Knickedi


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.

like image 45
Witek Avatar answered Sep 21 '22 14:09

Witek