在JAVA中将Base64字符串从JSONArray解码为字节列表
我有一个JSONArray,其中包含Base64格式的图像文件。在JAVA中将Base64字符串从JSONArray解码为字节列表,java,json,base64,Java,Json,Base64,我有一个JSONArray,其中包含Base64格式的图像文件。 image.add(new String(jsonobject.toString().getBytes("image_file"))); --> image.add(jsonobject.getJSONObject("machine_image").getString("image_file")); //correct 我想解码字节列表中的图像。 image.ad
image.add(new String(jsonobject.toString().getBytes("image_file"))); --> image.add(jsonobject.getJSONObject("machine_image").getString("image_file")); //correct
我想解码字节列表中的图像。
image.add(new String(jsonobject.toString().getBytes("image_file"))); --> image.add(jsonobject.getJSONObject("machine_image").getString("image_file")); //correct
我的json数组格式:
jsonarray:[{"manchine_image":{"image_file":"VW5pdHlGUw...}
我的现行守则:
List<String> image = new ArrayList<String>();
for(int i = 0; i < jsonarray.length();i++) {
JSONObject jsonobject = jsonarray.getJSONObject(i);
image.add(new String(jsonobject.toString().getBytes("image_file")));
}
无论如何,谢谢。这就是如何将Base64字符串解码为字节数组:
import java.util.Base64;
class Scratch {
public static void main(String[] args) {
String imageFile = "VW5pdHlGUw...";
byte[] decode = Base64.getDecoder().decode(imageFile);
}
}
我找到了答案。谢谢您的帮助。
image.add(new String(jsonobject.toString().getBytes("image_file"))); --> image.add(jsonobject.getJSONObject("machine_image").getString("image_file")); //correct