public static List <dynamic> JsonParser(string namefile) { fulltext = ReadFile(namefile); DeleteSpace(); elementGlobal = Parse(); Dictionary <string, object> dictionary = new Dictionary <string, object>(); List <dynamic> listDynamic = new List <dynamic>(); while (elementGlobal.Count > 0) { KeyValuePair <string, object> element = ElementPara(); dictionary.Add(element.Key, element.Value); if ("}]" == elementGlobal[0]) { dynamic dynamicObj = new Expando(); foreach (var valueDictionary in dictionary) { dynamicObj.Add(valueDictionary.Key, valueDictionary.Value); } listDynamic.Add(dynamicObj); dictionary = new Dictionary <string, object>(); } elementGlobal.RemoveAt(0); } return(listDynamic); }
static void MyTestExpando() { dynamic obj = new Expando() { { "clovo", "hello" }, { "chislo", 42 }, { "obect", new object() } }; int value = obj.chislo; obj.chislo = 22; Console.WriteLine(value); Console.WriteLine(obj.clovo + " " + obj.chislo); obj.Add("ifelse", true); if (obj.ifelse) { Console.WriteLine("obj.ifelse = " + obj.ifelse); } }
private static Object ToPersonalType(string str) { elementGlobal[0] = str; Dictionary <string, object> dictionaryInner = new Dictionary <string, object>(); while ("}" != elementGlobal[0]) { KeyValuePair <string, object> element = ElementPara(); dictionaryInner.Add(element.Key, element.Value); if ("}" == elementGlobal[0] || "}]" == elementGlobal[0]) { break; } elementGlobal.RemoveAt(0); } dynamic dynamicObj = new Expando(); foreach (var valueDictionary in dictionaryInner) { dynamicObj.Add(valueDictionary.Key, valueDictionary.Value); } return(dynamicObj); }