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h5e+tb75+f8BDQ0NDQ4NDhAQDhQWExYUHhsZGRseLSAiICIgLUQqMioqMipEPEk7NztJPGxVS0tVbH1pY2l9l4eHl761vvn5///AABEIBTQIWAMBIgACEQEDEQH/xACFAAEBAAMBAQEAAAAAAAAAAAAAAQIEBQMGBxABAAICAQMDAwMEAgIDAQADAAECAxEEBRIhEzFRFCJBFTJSI0JhcTNTJENygZFiJTShAQEBAQEBAAAAAAAAAAAAAAAAAQIDBBEBAQACAgIDAQEBAQEBAAAAAAECERITIVEDMUFhIjIjgVL/2gAMAwEAAhEDEQA/ANoE2yKbY7QGUyIbBWM31+WFrPGbbQes5YhhOTby0yiAXcykKaFDamtgppPMLACKRAGliFAQUBBkAw0x7XokgkQukiWQEQoAmiIUgGSaUBGSKKAoIKRAAGgUFBIjTIAVJUBF0KDGUhmAKABCgCgApEAAugQU0oMdCroE0mmWgGOjTNNAkKABpQECQEVPO1BBTQMVhQAABJZAMdGlUGOjTIBiqgIMkFY6TTMBjo0yAY6XSgJoUBBUkE15VYgBEirJRGOhkAxVSQYqKAACLBCgKADGWQCKAAKCKIAAAACCgAQoIKAgqAIqgmlEBQgAFARRQEBQAAABFF0DFQAVFBBRBBQEFFEUAAAE0oAAgAAigAAAKAgoDDbMAAAQXSAKAACgooICgIqAAACoAAAaUANAAAAAAAAigMZ2RKmgURQAAUABFQFAAAAAAABAUEFQBjMvLJaYidQ5mbPyv7KSuh19sbX1D5+2fqH8HjOXqF/7TVH0dcm3p3Q+exz1HX7Wzjx8+0+TVHZ2yamPHn/us24g0KKAhJLU5Fcto1STSNjug7nBy4edvxNnj6nMp+JB9J3bY98fL5q/J5cxqImGOSOZXWrzPgH0/ey7ny2GedN/O5h3cFM3ibmhvwEKgmmMs01CKAACiGwQUAAiQBQAAAQAFABFABQBEgAVABYUAABFAUAAAAAACAAAAkAAAAABAAAAYV/dIA9AAAAVAAAAAAQBVQAAEESQFIAB/9k="
]
如何将其转换为数组?
当我使用request.getParameterValues("jsondata");
时,会得到这个值[Ljava.lang.String;@8892fd8
,这是不期望的。
答案 0 :(得分:1)
jsondata
的值为JSON文本。它以[
开头,这意味着它是一个JSON数组。
要处理它,您应该使用JSON解析器。参见How to parse JSON in Java。
解析后,您应该具有两个值的String[]
或List<String>
。
两个值均以data:image/jpeg;base64,
开头,后跟Base-64编码的二进制数据(JPEG图像)。
假设您具有Java 8或更高版本,请使用Base64
类将其解码为byte[]
。
您现在拥有2个JPEG图像,格式为2字节数组。