传递变量的序列化问题 [英] Serialization problem in Passing variable

查看:65
本文介绍了传递变量的序列化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

当我将数组表单代码传递给JavaScript客户端时,我遇到了序列化问题。



C#中的代码

Hi every one,
I face a serialization problem when I pass an array form code behind into JavaScript client side.

the code in C#

public JavaScriptSerializer javaSerial = new JavaScriptSerializer();
public double [] label;
label = new double[numRow];
.....



javacript代码


the javacript code

var jsLabel = <%= this.javaSerial.Serialize(this.label); \\ the problem appear here <<< 







使用JSON JavaScriptSerializer进行序列化或反序列化时出错。字符串的长度超过maxJsonLength属性设置的值









当数组的大小非常大时出现问题

我尝试将以下内容添加到web.config文件中但它仍然不起作用






Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property




The problem appear when the size of array is very large
I try to add the following into web.config file but it still not work

<configuration>
   <system.web.extensions>
       <scripting>
           <webServices>
               <jsonSerialization maxJsonLength="50000000"/>
           </webServices>
       </scripting>
   </system.web.extensions>
</configuration>





请帮我解决这个问题



Please help me to solve this problem

推荐答案

根据文档:

According to the documentation:



的值MaxJsonLength属性仅适用于异步通信层用于调用Web服务方法的内部JavaScriptSerializer实例。


The value of the MaxJsonLength property applies only to the internal JavaScriptSerializer instance that is used by the asynchronous communication layer to invoke Web services methods.



如果您创建自己的实例 JavaScriptSerializer 类中, web.config 中的设置被忽略。



相反,你需要设置 MaxJsonLength 属性 [ ^ ]直接在您创建的实例上:


If you create your own instance of the JavaScriptSerializer class, the setting from web.config is ignored.

Instead, you need to set the MaxJsonLength property[^] directly on the instance you've created:

public JavaScriptSerializer javaSerial = new JavaScriptSerializer
{
    MaxJsonLength = 50000000
};


这篇关于传递变量的序列化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆