Define Parse(NodeValue jsonValue, Define define = null) { if (jsonValue == null) { return(define ?? new Define()); } if (jsonValue.Type == NodeValueTypes.Array) { return(Parse_Array(jsonValue)); } else if (jsonValue.Type == NodeValueTypes.Dictionary) { Define refer = new Define(); Parse_Dictionary(refer, jsonValue); return(refer); } else if (jsonValue.Type == NodeValueTypes.Object) { Define refer = new Define(); Parse_Object(refer, jsonValue); return(refer); } else if (jsonValue.Type == NodeValueTypes.String) { return(Parse_String(jsonValue)); } return(new Define()); }
/// <summary> /// 解析 /// </summary> /// <param name="value">仅支持string[]、string、{}、object、string(json)</param> /// <returns></returns> public Define Parse(object value) { Define result = value as Define; if (result != null) { return(result); } return(Parse(NodeValue.As(value))); }
void Parse_Object(Define define, NodeValue jsonValue) { //string[] pairs = new string[5]; //foreach (System.Reflection.PropertyInfo propertyInfo in jsonValue.ValueType.GetProperties()) { // string key = propertyInfo.Name; // if (string.Equals(key, "by", StringComparison.OrdinalIgnoreCase)) { // Parse_Pairs(pairs, 3, new JsonValue(propertyInfo.GetValue(jsonValue.Value, new object[0]))); // } else { // pairs[0] = key; // Parse_Pairs(pairs, 1, new JsonValue(propertyInfo.GetValue(jsonValue.Value, new object[0]))); // } //} //define.Add(Create_Pairs(pairs)); }
void Parse_Dictionary(Define define, NodeValue jsonValue) { //string[] pairs = new string[5]; //foreach (object item in (System.Collections.IEnumerable)jsonValue.Value) { // string key = FastWrapper.Get(item, "Key") as string; // if (string.IsNullOrEmpty(key)) // continue; // object value = FastWrapper.Get(item, "Value"); // if (string.Equals(key, "by", StringComparison.OrdinalIgnoreCase)) { // Parse_Pairs(pairs, 3, new JsonValue(value)); // } else { // pairs[0] = key; // Parse_Pairs(pairs, 1, new JsonValue(value)); // } //} //define.Add(Create_Pairs(pairs)); }
Define Parse_String(NodeValue jsonValue, Define define = null) { string value = jsonValue.Value as string; if (string.IsNullOrEmpty(value)) { return(define ?? new Define()); } //if (value[0] == '[' || value[0] == '{') { // return Parse(JSON.Parse(value), define); //} if (define == null) { define = new Define(); } Parse_String(define, value); return(define); }
Define Parse_Array(NodeValue jsonValue) { Define result = new Define(); foreach (object element in (System.Collections.IEnumerable)jsonValue.Value) { NodeValue item = new NodeValue(element); bool b = true; lb_Retury: if (item.Type == NodeValueTypes.Object) { Parse_Object(result, item); continue; } if (item.Type == NodeValueTypes.Dictionary) { Parse_Dictionary(result, item); continue; } if (!b) { continue; } if (item.Type == NodeValueTypes.String) { string text = item.Value as string; if (string.IsNullOrEmpty(text)) { continue; } Parse_String(item, result); if (text[0] == '[' || text[0] == '{') { item = new NodeValue(JSON.Parse(text)); b = false; goto lb_Retury; } continue; } } return(result); }
void Parse_String(Define define, string value) { if (value == "*") { define.Add(new DefineEntry("*", null, DefineValueTypes.Field)); return; } string[] pair = value.Split('='); if (pair.Length == 2) { DefineEntry item = new DefineEntry(pair[0], pair[1], DefineValueTypes.Field); ParseValue(item); define.Add(item); return; } { DefineEntry item = new DefineEntry(pair[0], pair[0], DefineValueTypes.Field); ParseValue(item); define.Add(item); } }