c# – 在序列化System.Globalization.CultureInfo类型的对象时检测到循环引用

前端之家收集整理的这篇文章主要介绍了c# – 在序列化System.Globalization.CultureInfo类型的对象时检测到循环引用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 jquery调用webservice,它返回一个包含几个表的数据集.

这工作正常,直到我需要设置我的webmethod接受参数.我在客户端反映了这一点

data: "{paramname:'" + paramval+ "'}",

我现在在webmethod返回时收到以下错误.无论数据集中返回什么,都会发生这种情况

Error:{“Message”:”A circular reference was detected while serializing
an object of type
\u0027System.Globalization.CultureInfo\u0027.”,”StackTrace”:” at
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object
o,StringBuilder sb,Int32 depth,Hashtable objectsInUse,
SerializationFormat serializationFormat)\r\n at …etc

当webmethod没有参数时,客户端js看起来与下面相同,除了data:line被删除.

function ClientWebService(paramval){
$.ajax({
    type: "POST",url: "WebService1.asmx/webmethodName",data: "{paramname:'" + paramval+ "'}",contentType: "application/json; charset=utf-8",dataType: "json",success: function(msg) {
        ParseResult(msg.d);
    },error: function(err) {
        if (err.status == 200) {
              ParseResult(err);
        }
        else { alert('Error:' + err.responseText + '  Status: ' + err.status); }
    }
});

}

编辑:根据建议将请求更改为

data: {paramname: paramval},

产生以下错误.

Error:{“Message”:”Invalid JSON primitive: paramval.”,”StackTrace”:”
at
System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\r\n
at
System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32
depth)\r\n at
System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String
input,Int32 depthLimit,JavaScriptSerializer serializer)\r\n 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](String
input)\r\n at
System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext
context,JavaScriptSerializer serializer)\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”} Status: 500

解决方法

我改变了我的webmethod返回
ds.GetXml();

这很有效.考虑到数据集是可序列化的,我不确定为什么我必须这样做,但它让我克服了这个障碍.

原文链接:https://www.f2er.com/csharp/99382.html

猜你在找的C#相关文章