本文介绍了如何反序列化复杂对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 在我的应用程序中,我将几个数组添加到一个新的Array对象中,然后通过AJAX发布数据。在myHandler中,我想将数据反序列化为数组。但是我在反序列化方面失败了。如果你知道如何反序化这样一个目标,我将不胜感激,如果你能分享你的知识。 var arrays = new 阵列(); arrays.push(ar1); // ar1 - Array arrays.push(ar2); // ar2 - 数组但与维度中的ar1不同 arrays.push(ar3); // ar3 - 数组,维度也不同 $ .ajax({ async: true , contentType:' application / json; charset = utf-8', dataType:' json',类型: POST, data:{arrays} , url: myHandler.ashx,成功: function (result){} }); // myHandler.ashx中的代码 public void ProcessRequest(HttpContext context) ){ context.Response.ContentType = application / json; var data = context.Request; var sr = new StreamReader(data.InputStream); var stream = sr.ReadToEnd(); var javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); vvar obj = javaScriptSerializer.DeserializeObject(stream); // 此处收到错误 以下是流的值: AR%5B0%5D%5B%5D = 8594&安培; AR%5B0%5D%5B%5D = K02R019&安培; AR%5B0%5D%5B%5D = K02&安培; AR%5B0%5D%5B%5D = IB-K- 29安培; AR%5B0%5D%5B%5D =车行道&安培; AR%5B0%5D%5B%5D = PRIVATE&安培; AR%5B0%5D%5B%5D =黄铜+ DISK&安培; AR%5B0%5D%5B%5D = &安培; AR%5B0%5D%5B%5D = 38.88722&安培; AR%5B0%5D%5B%5D = -77.09436&安培; AR%5B0%5D%5B%5D = K02&安培; AR%5B1%5D%5B0%5D %5B%5D = 5324&安培; AR%5B1%5D%5B0%5D%5B%5D = 8594&安培; AR%5B1%5D%5B0%5D%5B%5D = 222%2B54.45&安培; AR%5B1%5D%5B0 %5D%5B%5D = 22254.45&安培; AR%5B1%5D%5B0%5D%5B%5D =入境&安培; AR%5B1%5D%5B0%5D%5B%5D =安培; AR%5B1%5D%5B0%图5D%5B%5D =安培; AR%5B1%5D%5B0%5D%5B%5D = POT&安培; AR%5B2%5D%5B0%5D%5B%5D = 8594&安培; AR%5B2%5D%5B0%5D%图5B%5D = 8594&安培; AR%5B2%5D%5B0%5D%5B%5D = K02R019&安培; AR%5B2%5D%5B0%5D%5B%5D =安培; AR%5B2%5D%5B0%5D%5B% 5D = SET&安培; AR%5B2%5D%5B0%5D%5B%5D = 5%2F30%2F1905&安培; AR%5B2%5D%5B0%5D%图5B%5D = DUFF&安培; AR%5B2%5D%5B0%5D%5B%5D = ON + INVERT&安培; AR%5B2%5D%5B1%5D%5B%5D = 18059&安培; AR%5B2%5D%5B1%5D%图5B%5D = 8594&安培; AR%5B2%5D%5B1%5D%5B%5D = K02R019&安培; AR%5B2%5D%5B1%5D%5B%5D =安培; AR%5B2%5D%5B1%5D%5B% 5D = RECNORECORD&安培; AR%5B2%5D%5B1%5D%5B%5D =安培; AR%5B2%5D%5B1%5D%5B%5D =安培; AR%5B2%5D%5B1%5D%5B%5D = null& ar%5B3%5D%5B0%5D%5B%5D = 15015& ar%5B3%5D%5B0%5D%5B%5D = 8594& ar%5B3%5D%5B0%5D%5B%5D = 859 4& ar%5B3%5D%5B0%5D%5B%5D =& ar%5B3%5D%5B0%5D%5B%5D = NAD27VAN& ar%5B3%5D%5B0%5D%5B%5D = 447504.445&安培; AR%5B3%5D%5B0%5D%5B%5D = 2400018.492&安培; AR%5B3%5D%5B0%5D%5B%5D = NULL&安培; AR%5B3%5D%5B1%5D%5B%5D = 30701&安培; AR%5B3%5D%5B1%5D%5B%5D = 8594&安培; AR%5B3%5D%5B1%5D%5B%5D = 18059&安培; AR%5B3%5D%5B1%5D%5B%5D = PGIS&安培; AR%5B3%5D%5B1%5D%5B%5D = LDPNSRS2007&安培; AR%5B3%5D%5B1%5D%5B%5D = 169632.8118&安培; AR%5B3%5D%5B1%5D%5B%5D = 182628.1492&安培; ar%5B3%5D%5B1%5D%5B%5D = null 我有什么试过: 如何将复杂对象反序列化为数组?解决方案 In my app, I added several arrays into a new Array object, and then post the data through AJAX. In the myHandler, I want to deserialize the data into arrays. But I got failure in the deserialization. If you know how to for deserialize such an objective, I will appreciate if you can share your knowledge.var arrays = new Array();arrays.push(ar1); // ar1 - Arrayarrays.push(ar2); // ar2 - Array but different from ar1 in dimensionarrays.push(ar3); // ar3 - Array, also different in dimension$.ajax({ async: true, contentType: 'application/json; charset=utf-8', dataType: 'json', type: "POST", data: { arrays }, url: "myHandler.ashx", success: function (result) { }});// code in myHandler.ashxpublic void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; var data = context.Request; var sr = new StreamReader(data.InputStream); var stream = sr.ReadToEnd(); var javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); vvar obj = javaScriptSerializer.DeserializeObject(stream); // Got error hereBelow is the value of stream:"ar%5B0%5D%5B%5D=8594&ar%5B0%5D%5B%5D=K02R019&ar%5B0%5D%5B%5D=K02&ar%5B0%5D%5B%5D=IB-K-29&ar%5B0%5D%5B%5D=TRACKWAY&ar%5B0%5D%5B%5D=PRIVATE&ar%5B0%5D%5B%5D=BRASS+DISK&ar%5B0%5D%5B%5D=&ar%5B0%5D%5B%5D=38.88722&ar%5B0%5D%5B%5D=-77.09436&ar%5B0%5D%5B%5D=K02&ar%5B1%5D%5B0%5D%5B%5D=5324&ar%5B1%5D%5B0%5D%5B%5D=8594&ar%5B1%5D%5B0%5D%5B%5D=222%2B54.45&ar%5B1%5D%5B0%5D%5B%5D=22254.45&ar%5B1%5D%5B0%5D%5B%5D=INBOUND&ar%5B1%5D%5B0%5D%5B%5D=&ar%5B1%5D%5B0%5D%5B%5D=&ar%5B1%5D%5B0%5D%5B%5D=POT&ar%5B2%5D%5B0%5D%5B%5D=8594&ar%5B2%5D%5B0%5D%5B%5D=8594&ar%5B2%5D%5B0%5D%5B%5D=K02R019&ar%5B2%5D%5B0%5D%5B%5D=&ar%5B2%5D%5B0%5D%5B%5D=SET&ar%5B2%5D%5B0%5D%5B%5D=5%2F30%2F1905&ar%5B2%5D%5B0%5D%5B%5D=DUFF&ar%5B2%5D%5B0%5D%5B%5D=ON+INVERT&ar%5B2%5D%5B1%5D%5B%5D=18059&ar%5B2%5D%5B1%5D%5B%5D=8594&ar%5B2%5D%5B1%5D%5B%5D=K02R019&ar%5B2%5D%5B1%5D%5B%5D=&ar%5B2%5D%5B1%5D%5B%5D=RECNORECORD&ar%5B2%5D%5B1%5D%5B%5D=&ar%5B2%5D%5B1%5D%5B%5D=&ar%5B2%5D%5B1%5D%5B%5D=null&ar%5B3%5D%5B0%5D%5B%5D=15015&ar%5B3%5D%5B0%5D%5B%5D=8594&ar%5B3%5D%5B0%5D%5B%5D=8594&ar%5B3%5D%5B0%5D%5B%5D=&ar%5B3%5D%5B0%5D%5B%5D=NAD27VAN&ar%5B3%5D%5B0%5D%5B%5D=447504.445&ar%5B3%5D%5B0%5D%5B%5D=2400018.492&ar%5B3%5D%5B0%5D%5B%5D=null&ar%5B3%5D%5B1%5D%5B%5D=30701&ar%5B3%5D%5B1%5D%5B%5D=8594&ar%5B3%5D%5B1%5D%5B%5D=18059&ar%5B3%5D%5B1%5D%5B%5D=PGIS&ar%5B3%5D%5B1%5D%5B%5D=LDPNSRS2007&ar%5B3%5D%5B1%5D%5B%5D=169632.8118&ar%5B3%5D%5B1%5D%5B%5D=182628.1492&ar%5B3%5D%5B1%5D%5B%5D=null"What I have tried:How to Deserialize a complicate object into arrays? 解决方案 这篇关于如何反序列化复杂对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-03 05:04