我正在做一个项目,我试图向客户端返回一个带有图像和其他一些数据的 Json 对象,这可能吗?如果不是,如果我将图像作为字节数组或 base64 返回,前端将能够将其转换回实际图像,还是应该在我这边完成转换?
{
"author": "Uponn",
"title": "Some title",
"likes": 10000000,
"file": *image here*,
"uploadTime": null
}
最佳答案
答案是:取决于。
I'm doing a project of mine and I'm trying to return an Json object with an image and some other data to the client, is this possible?
您是定义应用程序 API/接口(interface)的人。如果您希望此服务返回包含该数据的 JSON 对象,那么可以:这是可能的。
当然。如果您明确指定该服务到底在做什么。所以:当你的后端从磁盘读取某些图像的原始字节,并将这些字节(以某种方式编码,可能使用 base64)放入字符串中时。当然,那么任何客户端都应该能够重新构建原始字节,然后根据用户想要使用这些信息的目的来处理这些信息。if I return the image as a byte array or base64 would a frontender be able to convert it
换句话来说:你所要求的一切在技术上都是不可能的。您要理解的关键是:我们无法告诉您您的要求。您必须确定人们为什么以及如何使用您的服务。然后您以支持商定的用例的方式设计它们。
关于java - 是否可以将一个 Json 对象中的图像和字符串返回给客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56295301/