如何将字节流图像数据放入JSON对象? [英] How to put byte stream image data into JSON object?
本文介绍了如何将字节流图像数据放入JSON对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用字节流格式将多个图像放在JSON对象中,我编写了以下代码。
I want to put multiple images in JSON object using byte stream format, i wrote the following code.
FileInputStream fin = new FileInputStream(pathToImages+"//"+"01.jpg");
BufferedInputStream bin = new BufferedInputStream(fin);
BufferedOutputStream bout = new BufferedOutputStream(out);
int ch =0; ;
sun.misc.BASE64Encoder encoder= new sun.misc.BASE64Encoder();
byte[] contents = new byte[5000000];
int bytesRead = 0;
String strFileContents;
while ((bytesRead = bin.read(contents)) != -1) {
bout.write(encoder.encode(contents).getBytes());
}
JsonObject myObj = new JsonObject();
我想将编码的字节流放在myObj中,但不知道该怎么做。
I want to put encoded byte stream in myObj,but dont know how to do it.
谢谢
推荐答案
JSONObject myObj = new JSONObject();
myObj.put("1",encoder.encode(contents).getBytes());
我认为这样可行。
这篇关于如何将字节流图像数据放入JSON对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文