如何覆盖maxstringlength以进行JSON.NET反序列化

时间:2013-11-06 16:16:10

标签: json web-services .net-3.5 json.net

尝试反序列化我的数据时,我得到以下异常:

  

{“Message”:“使用序列化或反序列化时出错   JSON JavaScriptSerializer。字符串的长度超过该值   在maxJsonLength属性上设置。\ r \ nParameter name:   输入“,”StackTrace“:”at   System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer   serializer,String input,Type type,Int32 depthLimit)\ r \ n at   System.Web.Script.Serialization.JavaScriptSerializer.Deserialize [T](字符串   输入)\ r \ n at   System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext的   context,JavaScriptSerializer序列化程序)\ r \ n at   System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData   methodData,HttpContext context)\ r \ n at   System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext的   context,WebServiceMethodData   methodData)”, “ExceptionType”: “System.ArgumentException”}

以下是代码:

Public Function Nominate(ByVal nominationRequest As String, ByVal nominee As String, ByVal coordinator As String) As Result
    Dim status As String = "ok"
    Dim messages As New List(Of String)

    Try
        Dim jsonSettings As JsonSerializerSettings = New JsonSerializerSettings()
        jsonSettings.NullValueHandling = NullValueHandling.Ignore
        jsonSettings.DefaultValueHandling = DefaultValueHandling.Ignore
        'jsonSettings.

        Dim jNomination As NominationRequest = JsonConvert.DeserializeObject(nominationRequest, GetType(NominationRequest), jsonSettings)
        Dim jNominee As Nominee = JsonConvert.DeserializeObject(nominee, GetType(Nominee), jsonSettings)
        Dim jCoord As Nominee = JsonConvert.DeserializeObject(coordinator, GetType(Nominee), jsonSettings)

        messages.AddRange(SaveNomination(jNomination, jNominee, jCoord))

    Catch ex As Exception
        status = "error"
        messages.Add(ex.ToString())
        ExceptionManagement.ExceptionManager.Publish(ex)
    End Try

    Dim result As Result = New Result()

    result.Status = status
    result.Messages = messages

    Return result
End Function

我只是希望它能够处理我所获得的巨型字符串作为参数。我最初使用的是版本4.5.14811并且已经更新到版本5.08.16617,希望它能解决我的问题(尽管更改日志没有给我太多的希望)。我使用的是.NET 3.5版本的DLL。如果您需要更多信息来帮助我,请告诉我。

由于

0 个答案:

没有答案