void Initilize(string file) { try { if (File.Exists(file)) { var jsonstr = ReadConfigTxt(file, false); var jsonobj = (JToken)SerH.JsonDeserialize(jsonstr); foreach (var filed in jsonobj) { switch (filed) { case JProperty jp: { if (sjon.ContainsKey(jp.Name)) { var jold = sjon[jp.Name]; if (jold.Type == null) { jold.Value = jp.Value; } else { if (jold.Type.TargetType != jp.GetType()) { jold.Value = Oct.ChangeType(jp.Value, jold.Type.TargetType); } else { jold.Value = jp.Value; } } } else { sjon[jp.Name] = new JsonItem() { Name = jp.Name, Value = jp.Value, Type = jp.GetType().GetTypeInfoN(), Desc = jp.GetType().GetXmlDescription() }; } } break; } } } } catch (Exception ex) { } }
//把字符串转化成JSON对象 void ParseJson(string JsonStr) { var JsonObjs = (JToken)SerH.JsonDeserialize(JsonStr); foreach (var itemfiled in JsonObjs) { switch (itemfiled) { case JProperty jp: if (summary.ContainsKey(jp.Name)) { var jold = summary[jp.Name]; if (jold.Type == null) { jold.Value = jp.Value; } else { if (jold.Type.TargetType != typeof(JProperty)) { try { jold.Value = Oct.ChangeType(jp.Value, jold.Type.TargetType); } catch { } } else { jold.Value = jp.Value; } } } else { summary[jp.Name] = new JsonItem() { Name = jp.Name, Type = jp.GetType().GetTypeInfoN(), Value = jp.Value }; } break; } } }