2014-10-19 44 views
0

我试图发送一个图像,我从数据库中取出,并且我想发送该图像,使用WebApi用PHP编写的JSON到Java程序;以下行是从PHP程序的提取物:从JAVA中提取对象JSON

$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

回答

0

如果我理解你的问题正确,你只需要像你在你的php代码中那样做相反的步骤。

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

感谢您的回复。这一切都很好! – 2014-10-20 19:20:40

+0

@JacopoTerrinoni我很高兴听到这个消息。您可以接受帮助他人找到解决方案的答案。 – user 2014-10-20 19:33:46

+0

这是系统的工作原理=> ** http://meta.stackexchange.com/a/5235/** @JacopoTerrinoni - 在发布另一个问题之前,您应该接受答案。 – 2014-10-20 19:34:57