[英]Extract an image from an object JSON in JAVA
我正在尝试使用数据库发送的图像,我想使用PHP和JSON编写的WebApi将图像发送到Java程序; 以下几行摘录自PHP程序:
$img = file_get_contents($stringPath);
$array = ["immagine" => base64_encode($img)];
echo json_encode($array);
在以下JAVA程序中,我使用restlet框架:
ClientResource resource = new ClientResource("link to the webApi");``
String retur = resource.get().getText();
JSONObject obj = new JSONObject(retur);
我如何从JSON对象中提取我从PHP progra发送的图像
如果我理解您的问题正确,那么您只需像在php代码中一样执行相反的步骤即可。
byte[] content = Base64.decodeBase64(obj.getString("immagine"));
ByteArrayInputStream bais = new ByteArrayInputStream(content);
BufferedImage image = ImageIO.read(bais);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.