是否可能或合理地将位图数据编码为JSON以在Web服务中返回?
更新:是的,这比我想象的要好.我为一组图像和图像数据组合创建了一个.NET复合对象
Public Class AllThumbnails Public imgAllThumbs As String Public positions()As Drawing.Rectangle End Class
并通过jQuery AJAX访问它:
$.ajax({
type: "POST",
url: "WebService.asmx/makeAllThumbnailsImage",
data: "{DocumentNumber : \"" + DocumentNumber + "\"} ",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var adl = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
var data = Base64.decode(adl.imgAllThumbs);
$('#output').append("<p><strong>" + data.length + "</strong></p>");
$('#output').append("<p><strong><i>" + adl.positions.length + "<i></strong></p>");
},
failure: function (msg) {
$('#output').text(msg);
}
});
Run Code Online (Sandbox Code Playgroud)
因为我的图像数据超出了标准的jsonSerialization缓冲区,所以我必须在web.config中增加一个值:
<system.web.extensions>
<scripting>
<webServices> …