diff --git a/Ext.Direct.sln b/Ext.Direct.sln index 5d34e35..233c63b 100644 --- a/Ext.Direct.sln +++ b/Ext.Direct.sln @@ -1,6 +1,6 @@  -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ext.Direct", "Ext.Direct\Ext.Direct.csproj", "{653B211D-FEFA-483B-A284-6431C8598ED4}" EndProject Global diff --git a/Ext.Direct/ComplexObjectConverter.cs b/Ext.Direct/ComplexObjectConverter.cs index 79d2d74..49ab089 100644 --- a/Ext.Direct/ComplexObjectConverter.cs +++ b/Ext.Direct/ComplexObjectConverter.cs @@ -16,7 +16,7 @@ public override bool CanConvert(Type objectType) return false; } - public override object ReadJson(JsonReader reader, Type objectType) + public override object ReadJson(JsonReader reader, Type objectType, object existingValue=null, JsonSerializer serializer=null) { if (reader.TokenType == JsonToken.StartArray) return ReadArray(reader); @@ -87,7 +87,7 @@ private object ReadObject(JsonReader reader) return null; } - public override void WriteJson(JsonWriter writer, object value) + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer=null) { throw new NotImplementedException(); } diff --git a/Ext.Direct/DirectProcessor.cs b/Ext.Direct/DirectProcessor.cs index 82f7e6f..dce5be6 100644 --- a/Ext.Direct/DirectProcessor.cs +++ b/Ext.Direct/DirectProcessor.cs @@ -7,6 +7,7 @@ using Newtonsoft.Json.Converters; using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Linq; +using System.Text.RegularExpressions; namespace Ext.Direct { @@ -42,16 +43,29 @@ internal static DirectExecutionResponse Execute(DirectProvider provider, HttpReq { UTF8Encoding encoding = new UTF8Encoding(); string json = encoding.GetString(httpRequest.BinaryRead(httpRequest.TotalBytes)); - List requests = JsonConvert.DeserializeObject>(json); - if (requests.Count > 0) + /************************************************************************************** + skygreen:解决bug:Self referencing loop + 参考:http://stackoverflow.com/questions/7397207/json-net-error-self-referencing-loop-detected-for-type + **************************************************************************************/ + if (substr_count(json,"data")>1) { - JArray raw = JArray.Parse(json); - int i = 0; - foreach (DirectRequest request in requests) + List requests = JsonConvert.DeserializeObject>(json); + if (requests.Count > 0) { - request.RequestData = (JObject) raw[i]; + JArray raw = JArray.Parse(json); + int i = 0; + foreach (DirectRequest request in requests) + { + request.RequestData = (JObject)raw[i]; + responses.Add(DirectProcessor.ProcessRequest(provider, request)); + ++i; + } + } + else + { + DirectRequest request = JsonConvert.DeserializeObject(json); + request.RequestData = JObject.Parse(json); responses.Add(DirectProcessor.ProcessRequest(provider, request)); - ++i; } } else @@ -62,7 +76,11 @@ internal static DirectExecutionResponse Execute(DirectProvider provider, HttpReq } } DirectExecutionResponse response = new DirectExecutionResponse(); - JsonSerializerSettings outputSettings = new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore }; + + JsonSerializerSettings outputSettings = new JsonSerializerSettings() { + DefaultValueHandling = DefaultValueHandling.Ignore, + ReferenceLoopHandling =ReferenceLoopHandling.Ignore + }; foreach (JsonConverter converter in converters) { outputSettings.Converters.Add(converter); @@ -80,6 +98,41 @@ internal static DirectExecutionResponse Execute(DirectProvider provider, HttpReq return response; } + /// + /// 计算字符串出现的次数 + /// + /// 必需。规定要检查的字符串。 + /// 要搜索的字符串 + /// 查找方式,默认0:正则表达式方式,这种方式如果子字符串有特殊符号不推荐用;其他:标准的查找子字符串的方式 + /// + public static int substr_count(string haystack, string needle,int type=0) + { + + int count = 0; + if (type == 0) + { + if (haystack != String.Empty && needle != String.Empty) + { + MatchCollection mc = Regex.Matches(haystack, needle); + count = mc.Count; + } + } + else + { + for (int i = 0; i < haystack.Length; i++) + { + for (int j = 1; j <= (haystack.Length - i); j++) + { + if (haystack.Substring(i, j) == needle) + { + count++; + } + } + } + } + return count; + } + private static DirectResponse ProcessRequest(DirectProvider provider, DirectRequest request) { DirectResponse r = new DirectResponse(request); diff --git a/Ext.Direct/Ext.Direct.csproj b/Ext.Direct/Ext.Direct.csproj index cbac143..43fdc5e 100644 --- a/Ext.Direct/Ext.Direct.csproj +++ b/Ext.Direct/Ext.Direct.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -10,8 +10,29 @@ Properties Ext.Direct Ext.Direct - v3.5 + v4.5 512 + + + + + 3.5 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true true @@ -21,6 +42,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -29,11 +51,12 @@ TRACE prompt 4 + false False - ..\..\..\newton\Bin\Newtonsoft.Json.dll + ..\..\Betterlife.Net\Library\Newtonsoft.Json.dll @@ -72,6 +95,18 @@ + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + true + +