[英]Extract an image from an object JSON in JAVA
i'm trying to send an image that i took from a database and i would like to send that image, using a WebApi written in PHP with JSON to a Java program; 我正在尝试使用数据库发送的图像,我想使用PHP和JSON编写的WebApi将图像发送到Java程序; the following lines are an extract from PHP program: 以下几行摘录自PHP程序:
$img = file_get_contents($stringPath);
$array = ["immagine" => base64_encode($img)];
echo json_encode($array);
in the following JAVA program i use restlet framework: 在以下JAVA程序中,我使用restlet框架:
ClientResource resource = new ClientResource("link to the webApi");``
String retur = resource.get().getText();
JSONObject obj = new JSONObject(retur);
How can i extract from the JSON object the image that i sent from the PHP progra 我如何从JSON对象中提取我从PHP progra发送的图像
If i understand your question correct you just have to do the reverse step like you are doing in your php code. 如果我理解您的问题正确,那么您只需像在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.