將位圖數據編碼爲JSON以便在Web服務中返回是否可能或合理?JSON位圖數據
更新:是的,這比我想象的更好。餘由.NET複合對象的圖像的組合與圖像數據一起
公共類AllThumbnails 公共imgAllThumbs作爲字符串 公共位置()作爲Drawing.Rectangle 末級
和通過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);
}
});
我也紛紛加大對我的web.config的值,因爲我的圖像數據是超越標準jsonSerialization緩衝:
<system.web.extensions> <scripting> <webServices> <jsonSerialization maxJsonLength="262144"> </jsonSerialization> </webServices> </scripting> </system.web.extensions>
謝謝你們的幫助。
對不起 - 應該說。我使用C#.NET和Javascript和jQuery。 – 2010-05-21 02:14:35
這是沒有問題的。您只需編輯您的帖子,然後根據需要添加/刪除標籤即可。我會爲你添加它們,因爲這是一箇舊帖子。 – jlafay 2012-01-19 15:08:22