Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从JAVA中的JSON对象提取图像_Java_Php - Fatal编程技术网

从JAVA中的JSON对象提取图像

从JAVA中的JSON对象提取图像,java,php,Java,Php,我正在尝试发送一个从数据库中获取的图像,我想使用一个用PHP编写的带有JSON的WebApi将该图像发送到一个Java程序;以下几行是PHP程序的摘录: $img = file_get_contents($stringPath); $array = ["immagine" => base64_encode($img)]; echo json_encode($array); 在以下JAVA程序中,我使用restlet框架: ClientResource resource = new Cli

我正在尝试发送一个从数据库中获取的图像,我想使用一个用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程序发送的图像如果我理解您的问题正确,您只需像在PHP代码中那样执行相反的步骤

byte[] content = Base64.decodeBase64(obj.getString("immagine"));
ByteArrayInputStream bais = new ByteArrayInputStream(content);
BufferedImage image = ImageIO.read(bais);

@我很高兴听到这个消息。你可以接受答案以帮助他人找到解决方案。以下是系统的工作原理=>@jacopoterinoni-在发布其他问题之前,你应该接受答案。