日期:2014-05-18  浏览次数:20429 次

Ajax转码问题
上代码:
JScript code

//对象转换json格式
 function _SealInfo() {
     var obj = new Object();
     obj.SAssessID = "-1";
     obj.SUserID = "-1";
     obj.DAddTime = "1900-01-01";
     obj.SAssessName =escape(projectName);
     obj.FCollectingArea = lab_fBuildArea;
     obj.FPlanningArea = SumArea;
     obj.SPlotRatio = escape(rjl);
     obj.SConforming = escape(Conforming);
     obj.SConformingID = escape(sConformingID);
     obj.SProvince = escape(sProvince);
     obj.SCity = escape(sCity);
     obj.IParcelArea = CityCode;
     obj.FAssessPrice_Market = fAssessPrice_Market;
     obj.FTotalPrice_Market = fTotalPrice_Market;
     obj.FAssessPrice_Assume = fAssessPrice_Assume;
     obj.FTotalPrice_Assume = fTotalPrice_Assume;

     //判断
     obj.IDistance_Markey = iDistance;
     obj.ITimelimit_Markey = iTimelimit;
     obj.IDistance_Assume = iDistance;
     obj.ITimelimit_Assume = iTimelimit;

     obj.IItemCount_Markey = arr1.length;
     
     obj.IItemCount_Assume = arr2.length;
     //假设开发法参数
     obj.FExpenseRatio = -1;
     obj.FMargin =-1;
     obj.FCosts = -1;
     obj.FIncrease = -1;
     obj.IState = State;
     return $.toJSON(obj);
 }
 function UrlAjax(type) {
     var infoJson = _SealInfo();
     $.post("Agent/LandAssessDBdetail.ashx", { AssessAjaxtype: type, info: infoJson }, function(msg) { 
        
     })



后台ashx
C# code

JavaScriptSerializer js =new JavaScriptSerializer();
            LandAssess_BasicInfoClass info = js.Deserialize<LandAssess_BasicInfoClass>(context.Server.HtmlDecode(context.Request.Form["info"]));


后台接收转成对象了但是还是编码的数据。求解

------解决方案--------------------
//将Json字符串转化成对象
DataContractJsonSerializer outDs = new DataContractJsonSerializer(typeof(LandAssess_BasicInfoClass));
using (MemoryStream outMs = new MemoryStream(Encoding.UTF8.GetBytes(context.Request.Form["info"])))
{
 LandAssess_BasicInfoClass info = outDs.ReadObject(outMs) as LandAssess_BasicInfoClass; 

------解决方案--------------------
探讨

引用:

obj.SAssessName =escape(projectName);
是何种用意呢?规避汉字乱码?

是的。开始的时候不转码到后台就会乱码