gpt4 book ai didi

java - 为什么 Byte [] 在 JSON View 中被转换为 String

转载 作者:行者123 更新时间:2023-11-29 03:32:51 25 4
gpt4 key购买 nike

我正在使用 spring MVC 生成一个 JSON View ,java 对象中的属性之一是字节数组

public class Profile {

private String profId;
private byte[] image;
....
}

我正在将 spring View 设置为 json View

    ModelAndView mav = new ModelAndView("jsonView");
Profile res = profService.get(profId);
mav.addObject("prof", res);
return mav;

我调试了一切正常,直到我返回 mav(它有字节数组[])

[-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 61, 0, 0, 0, 99, 8, 2, 0, 0, 0, -89, -124, -97, 57, 0, 0, 0, 1, 115, 82, 71, 66, 0, -82, -50, 28, -23, 0, 0, 0, 4, 103, 65, 77, 65, 0, 0, -79, -113, 11, -4, 97, 5, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, -61, 0, 0, 14, -61, 1, -57, 111, -88, 100, 0, 0, 6, 86, 73, 68, 65, 84, 120, 94, -19, -101, -49, -53, -107, 69, 20, -57, -3, 15, 91, -75, 105, -43, -90, 85, 27, 87, 109, 90, -71, 40, 8, 114, -31, 66, 34, -56, 69, 65, 68, -32, 34, 34, -56, 69, -94, 89, -111, -46, 15, -92, -92, -92, -62, 34, 67, 43, -59, 8, 19, 17, 9, -5, -64, -9, 114, -18, -68, -49, 125, 102, -26, -52, 121, 102, 46, -49, -123, -28, 89, 120, 95, -26, -103, -7, -52, 119, -50, -100, 57, -25, -36, -71, -57, -98, 28, -26, -65, 99, -121, -119, -3, -28, 127, -18, -3, 46, -36, 88, -67, 111, -36, -66, -1, -19, -49, -9, -50, 95, -67, -11, -50, -59, 27, 60, 31, 126, -7, 27, 31, 121, -106, -49, -79, 63, -9, -93, -57, -1, 94, -70, -10, -5, -87, -9, -66, 123, -10, -28, 39, 79, -99, 56, 63, -5, 60, -13, -54, -57, -81, -98, -67, -58, 124, -18, -35, 127, 20, -101, 67, 103, 110, 20, -99, -32, 62, 119, -22, -77, 23, -33, -4, -38, -98, -25, 79, 127, -98, -50, -124, 9, -68, 127, -7, 87, -90, -38, 74, -33, -115, -5, -6, -51, -65, -113, -65, 126, -59, -104, -48, -5, -14, -9, 127, -26, -28, -92, -15, 107, 31, 92, 7, 90, -19, -103, 27, -115, -101, -48, -5, 112, 99, 24, 79, -65, 116, 65, 16, 47, -65, -5, -51, -51, 59, 15, 60, 16, -56, -100, -82, -49, 27, -25, 126, -16, -68, -91, 54, 29, -72, -33, -6, -24, 39, 17, -97, 120, -5, 42, 27, -47, 63, -74, 90, -2, -13, -16, 49, -38, -37, -100, -7, -24, -23, 97, 41, -73, 65, 99, 24, -98, -15, 114, 109, -80, 19, -83, 24, 59, -63, 99, -18, -117, -72, 49, 15, -23, -76, 16, 90, -109, -7, -22, -57, -69, 66, 71, -2, -86, 4, 113, 110, -10, -106, -122, -23, 2, 109, -24, 18, 2, 39, 83, 70, 15, 114, -77, -108, -14, 30, -40, 116, 85, -101, -90, 6, 28, 79, 116, -117, 34, 101, -41, 30, -28, 70, 15, 9, 19, -40, -120, -27, 105, -104, 34, 101, -9, 18, -31, -90, 107, 29, 46, -72, -68, 38, 45, -99, -115, -39, -93, 85, 81, 34, -36, -100, -49, -43, 126, -99, -120, -71, 102, 50, -62, -126, -28, 17, 110, 66, -117, 113, 98, 107, 38, -78, 67, -126, -126, -36, -60, -102, -71, 49, 18, -99, -49, -83, 39, 115, -45, 10, 48, -118, -106, -12, -113, -65, 30, -50, -66, -40, -52, -115, -5, 83, -113, -50, -125, -83, 9, 55, 109, 44, 83, 57, -5, -23, 47, 125, -72, -75, 105, -24, 52, 12, -28, 124, 17, -29, 46, -104, 120, -77, -34, 56, 62, 92, 44, 91, -45, 57, 124, -72, -103, 76, 60, -25, -78, -102, -71, -61, 28, -83, 47, -54, 107, -67, 112, -26, -117, 62, 118, -46, 58, 124, -72, -67, -72, 115, 46, 101, -19, 122, 19, 30, 30, -104, -34, -118, -112, 115, 65, -37, 122, -11, 102, 71, -62, 13, -3, -127, -23, 77, -46, 9, 119, -82, 104, -79, 82, -67, 117, -70, 113, 48, -25, 114, -97, -107, 114, 99, -42, -27, -32, 126, -115, -36, 100, 12, -54, -92, 10, 33, 80, -112, 91, -27, 50, 85, -49, 116, 124, -14, -111, -59, 13, 123, -21, -12, 69, -119, 93, 8, 6, 105, -36, -64, 77, 85, -124, -77, -105, -60, -52, 74, 37, 10, -80, -46, -121, 124, 66, 21, -97, -16, 4, -104, -65, 58, 44, 119, -30, -30, 38, 38, -111, 87, 74, 31, -12, 72, 11, 104, 105, -79, -118, 102, 120, 3, -78, -3, 86, 122, 98, 76, -71, -111, 106, -82, 93, -31, -90, 35, 101, 9, 122, -128, -61, 42, 114, 57, 37, 118, -119, -63, -92, -19, 89, 28, 127, -27, -110, -79, 52, 121, 22, -83, 26, 36, -105, -72, -79, 87, -51, 94, 113, -103, 63, 5, 38, -40, -89, 6, 34, 115, 2, -126, -62, 72, 85, 120, -90, 39, 104, 124, -97, 103, -96, 44, 55, -90, -84, -127, 65, -113, 85, -84, 65, -63, -112, 60, 28, 76, 76, -119, -74, -89, -79, 36, -104, -25, -74, -52, -105, -127, -85, 75, 86, -42, 50, -105, 104, -23, 45, -83, -116, -106, -108, 13, -29, 81, 58, -53, -35, 84, -17, -86, 26, -64, -92, 1, -25, 31, -96, -72, 38, -42, 80, -2, 78, 15, -69, -94, 73, -96, -87, -34, -12, -88, -76, 119, 68, 109, 4, 104, 118, -22, -60, 47, 97, -42, 1, -65, 57, -27, -106, -65, 99, -55, -102, 102, -17, 84, 125, -30, 76, -7, 24, 32, -98, -79, 19, 79, -95, -56, -119, 56, -37, 76, 22, -120, 40, -72, 118, 79, -79, -72, 48, -42, 17, -67, -11, -27, -53, 8, 11, 49, 2, -48, -53, 59, -43, -87, -53, -106, -37, 14, 88, -1, -90, 118, -114, 49, -94, -39, -106, 91, -2, -88, 122, -64, -114, -128, 8, -12, -71, -27, -106, -25, -33, 67, 97, 36, 64, -71, -5, -54, -122, 27, -37, -112, 123, 26, -31, 70, -70, -128, 78, 58, -39, 112, -53, -109, 112, -92, -113, 24, 99, 68, -97, 27, 110, 21, -75, 114, -59, -95, 17, 3, 47, -20, 115, -61, -83, 34, -30, 80, 15, -72, 16, 116, -34, 78, -60, 125, 40, -50, 100, 27, 15, 82, 102, -122, -69, -5, -105, 99, 125, 53, 78, 123, -37, -40, 73, -71, -120, 56, 110, -8, 112, -49, 27, 110, -114, 95, -123, -19, -31, -114, -10, -4, -30, -122, 27, -73, -83, -20, 38, -106, -38, -20, 25, 122, 107, -33, -4, -113, -44, 6, -18, 92, 29, 113, -1, 100, -27, 17, -73, -25, -68, 92, -8, -95, 28, 61, 91, 110, -5, 22, -8, 32, 66, -108, 35, -15, -73, 36, 39, -64, 90, 24, -44, -17, -63, -88, -114, 112, -101, -28, -98, 27, 32, 101, 56, 54, 58, 73, 13, 69, 34, -50, -32, -76, -84, -91, -37, 120, -2, 98, 80, 110, -108, 105, 126, 105, 21, -120, -80, -75, 16, -94, 105, -117, -105, 31, -46, -31, -40, 77, 54, -51, 100, -90, 126, -94, 51, 31, -73, -24, -87, 51, -91, 122, 64, -100, 86, 9, -39, -30, 116, -123, -64, 28, -58, -72, 87, 100, -26, -1, -4, 37, -67, -118, -121, 77, -58, -24, -25, -21, 62, 18, -116, 99, -56, 89, -101, 100, -35, -119, 37, 37, 48, 40, -128, -106, -81, -76, -111, 98, -126, 107, -109, -28, -107, -42, 26, -12, 60, 55, -42, 105, -123, 14, -126, -83, -14, 54, 5, -38, -86, 100, 16, 55, -19, 105, -84, 81, 37, 72, -106, -105, 5, -15, 111, -24, 82, 93, 83, 6, -93, 114, 74, -39, -36, 49, 0, -60, -117, 37, -22, -52, -45, 74, -72, -2, 83, -81, 82, 71, 6, -41, -18, -115, -54, 0, 88, 10, -42, 52, 119, 77, -63, 47, -40, -92, -91, 2, 82, -98, -22, -115, -80, -20, -66, -100, -12, 8, 40, 114, -18, 126, -57, -64, 31, -61, -108, -77, 47, -38, -99, 45, -113, 63, 112, 125, -33, -64, 48, 24, 49, -96, -109, 91, -71, 78, 109, -4, -45, 83, 45, 4, 127, 80, 117, -16, 94, 110, 27, 27, 35, 102, 77, -23, -102, -3, 20, 51, -24, -62, 52, -80, 117, -7, -91, -22, 93, -39, 102, 110, -115, -118, 127, -20, 14, -83, -98, 85, 17, 25, 117, 127, -48, -65, -12, -127, -106, 42, -37, -106, 99, -115, -96, -34, 1, 26, -1, 43, -86, 84, 34, 121, -95, 8, -75, 70, 110, 102, 40, -25, 91, 56, -83, 87, -54, 93, 45, -78, -82, -108, -69, 90, -9, 91, 41, -73, -18, 113, 96, -30, -34, -8, -37, -65, 123, -122, -74, -60, -55, -106, -21, -61, 43, -43, 27, 81, -60, -35, -19, -98, -23, 80, -103, -83, 115, 60, -96, -72, 115, 7, 126, -77, -34, 74, 41, -70, 71, 38, 19, 57, -20, 123, -124, 110, -10, -83, 88, -39, 31, 40, -57, -42, 71, 117, -65, 66, 49, -89, 89, 111, -3, -2, 32, 119, 29, 49, 70, -71, -5, 86, 117, -108, 102, 110, -117, 123, -122, 126, 19, -92, -88, -80, 96, -115, -51, -36, 104, -93, -116, 48, 92, -88, -88, -82, -119, 57, -63, 66, -56, 25, -31, -42, 13, -48, 113, 95, -86, 40, -15, 41, 95, 49, -113, 112, 123, -18, -55, 85, 69, -51, 53, 112, 118, 30, -31, 102, 72, -91, -6, 35, 110, -35, 59, 123, 14, 114, 91, 37, -79, -81, 67, -108, -5, -29, -87, -34, -17, 8, 114, 35, -71, 93, -6, 112, -42, -76, -86, -106, 99, 87, 118, -86, -55, 37, 93, -59, -71, 121, -39, 126, 75, 86, -107, -57, 3, 45, 55, -27, 60, 25, 22, 113, 67, 99, 87, 120, -106, 84, -126, 48, 15, 93, -114, 2, -35, 121, 44, 44, -27, -74, 61, 42, -49, -40, -102, -28, 67, 105, -65, 60, 109, -70, 59, -41, -127, 27, 116, -50, 32, 43, 104, 97, -99, -98, -33, 23, -29, -17, -16, -45, -10, -45, -24, -42, 111, 10, -6, 112, -85, -18, -111, 94, -5, -94, -78, -123, -11, -109, -103, -89, 115, 96, 53, -8, 11, -72, 105, 97, -65, -49, 125, -74, -22, 6, 42, 55, -128, 126, -9, -90, -99, 92, -37, -18, -61, -36, -62, 27, -70, -101, -34, -23, 124, -48, -107, 98, 118, 110, 2, 8, 92, 45, -20, 87, -27, 27, -62, 61, 25, 85, -26, -47, -9, -70, -39, 62, -72, -85, -30, 5, 26, 28, 42, -9, 127, -70, 49, -102, 79, -12, 30, -24, -86, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126]

但是当我在浏览器上检查 JSON 响应时,它得到的是字符串而不是数组

{
"prof": {
"profId": "Test123",
"image": "ODk1MDRFNDcwRDBBMUEwQTAwMDAwMDBENDk0ODQ0NTIwMDAwMDAzRDAwMDAwMDYzMDgwMjAwMDAwMEE3ODQ5RjM5MDAwMDAwMDE3MzUyNDc0MjAwQUVDRTFDRTkwMDAwMDAwNDY3NDE0RDQxMDAwMEIxOEYwQkZDNjEwNTAwMDAwMDA5NzA0ODU5NzMwMDAwMEVDMzAwMDAwRUMzMDFDNzZGQTg2NDAwMDAwNjU2NDk0NDQxNTQ3ODVFRUQ5QkNGQ0I5NTQ1MTRDN0ZEMEY1QkI1NjlENUE2NTUxQjU3NkQ1QUI5MjgwODcyRTE0MjIyQzg0NTQxNDRFMDIyMjJDODQ1QTI1OTkxRDIwRkE0QTRBNEMyMjI0MzJCQzUwODEzMTEwOUZCQzBGNzcyRUVCQ0NGN0Q2NkU2Q0M3OTY2MkVDRjg1RTQ1OTc4NUZFNjk5RjlDQzc3Q0U5QzM5RTdEQ0I5Qzc5RTFDRTZCRjYzODc4OUZERTQ3RkVFRkQyRURDNThCRDZGRENCRUZGRURDRkY3Q0U1RkJERjVDRUM1MUIzQzFGN0VGOTFCMUY3OTk2Q0ZCMTNGRjdBM0M3RkY1RUJBRjZGQkE5RjdCRTdCRjZFNDI3NEY5RDM4M0ZGQjNDRjN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UxQjUxQzREREVEOUVFOTUwOTlBRDczM0NBMEI4NzMwNzdFQjNERTRBMjlCQTQ3MjYxMzM5RUM3Qjg0NkVGNkFENThEOTFGMjhDN0Q2NDc3NUJGNDIzMUE3NTk2RkZERkUyMDc3MUQzMTQ2QjlGQjU2NzU5NDY2NkU4QjdCODY3RTEzQTRBOEIwNjA4RENEREM2OEEzOEMzMDVDQThBOEFFODkzOUMxNDJDODE5RTFENjBERDA3MTVGQUEyOEYxMjk1RjMxOEY3MDdCRUVDOTU1NDVDRDM1NzA3NjFFRTE2NjQ4QTVGQTIzNkVERDNCN0IwRTcyNUIyNUIxQUY0Mzk0RkJFM0E5REVFRjA4NzIyM0I5NURGQTcwRDZCNEFBOTY2MzU3NzZBQUM5MjU1REM1Qjk3OUQ5N0U0QjU2OTVDNzAzMkQzN0U1M0MxOTE2NzE0MzYzNTc3ODk2NTQ4MjMwMEY1RDhFMDJERDc5MkMyQ0U1QjYzRDJBQ0ZEODlBRTQ0MzY5QkYzQzZEQkEzQkQ3ODExQjc0Q0UyMDJCNjg2MTlEOUVERjE3RTNFRkYwRDNGNkQzRThENjZGMEFGQTcwQUJFRTkxNUVGQkEyQjI4NUY1OTM5OUE3NzM2MDM1RjgwQkI4Njk2MUJGQ0Y3REI2RUEwNjJBMzc4MDdFRjdBNjlENUNEQkVFQzNEQ0MyMUJCQTlCREVFOTdDRDA5NTYyNzY2RTAyMDg1QzJERUM1N0U1MUJDMjNEMTk1NUU2RDFGN0JBRDkzRUI4QUJFMjA1MUExQzJBRjc3RkJBMzE5QTRGRjQxRUU4QUEwMDAwMDAwMDQ5NDU0RTQ0QUU0MjYwODI=",
"cretDt": "06-19-2013 12:16:25",
"state": 6002,
"stateName": "Approved"
}
}

数组在哪里?

谁能帮我在浏览器上重新获取 byte[]。

最佳答案

您的数据在那里,它们只是编码为 base64出于性能原因(查看 this comparison )。您为此付出的代价是在客户端对其进行解码所需的开销(但您将节省很多带宽和时间)。

我强烈建议您将它们保留为该格式(因为它比普通 JSON 数组 表示更紧凑)。您可以使用一个简单的库在 JavaScript 中对它们进行解码,以对 base64 进行编码/解码。例如this one .

如果您真的需要以这种方式序列化您的数组,那么请更改您的序列化库(例如 Gson 以您需要的方式序列化它们)或自定义您正在使用的库。例如,用于自定义序列化的 FlexJSON 有一个名为 Transformers 的强大机制。 .只需编写您自己的转换器来覆盖 byte[] 的默认 ArrayTransformer 行为,实现与 IterableTransformer 相同的逻辑,您就可以完成。

编辑
在您的 fiddle 中,您正在解码为字符串,算法与解码为数组并无不同,让我们开始将解码函数更改为:

decode : function (input) {
var output = [];

for (i = 0; i < input.length; i += 4) {
a = this._keyStr.indexOf(input[i]);
b = this._keyStr.indexOf(input[i + 1]);
c = this._keyStr.indexOf(input[i + 2]);
d = this._keyStr.indexOf(input[i + 3]);


output.push((a << 2) | (b >> 4));
output.push(((b & 15) << 4) | (c >> 2));
output.push(((c & 3) << 6) | (d & 63));
}

return output;
}

请注意,这只是一个解释算法的示例,它不执行任何检查,它不删除填充 而且它甚至非常慢。更合适的解决方案是在(或使用 ArrayBuffer)之前分配完整数组,因为最终数组大小可以根据输入字符串长度计算得出。 Look herehere完整实现。

关于java - 为什么 Byte [] 在 JSON View 中被转换为 String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17199672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com