简体   繁体   English

Android-如何在宁静的Web服务上以JSON格式传输图像

[英]Android - How to transfer images on restful web services as json

I have a model like; 我有一个像

public class Employee{
      String name;
      int age;
      String designation;
      double salary;
      ...........

and there will be another field; 并且会有另一个领域; employee's photo 员工的照片

here is my question; 这是我的问题; how can I transfer this employee object or employee list object with restful web service as json object. 如何将带有宁静的Web服务的此员工对象或员工列表对象作为json对象进行传输。 I can convert my images(employee's photo) to String but is this best way to transfer image files.Could anyone give me an example about transfering image files in java models 我可以将我的图像(员工的照片)转换为String,但这是传输图像文件的最佳方法。有人可以给我一个在Java模型中传输图像文件的示例吗?

JSON isn't built to stream raw data such as images. JSON并非用于流式传输原始数据(例如图像)。 The best practice to do what you need is to supply a link to the image in the json field (a simple URL) and then download that image separately. 进行所需操作的最佳实践是在json字段(简单的URL)中提供指向图像的链接,然后分别下载该图像。 The image itself can be stored raw "as is". 图像本身可以原始存储。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM