예제 #1
0
        public static void FlattenJsonByPath()
        {
            string line = string.Empty;

            using (var rd = new StreamReader(@".\sampleJson"))
            {
                line = rd.ReadLine();
            }

            //var jsonPaths = JsonFlatten.FlattenJsonByPath(line, "nodeKey.Events.Name");
            var jsonPaths = JsonFlatten.FlattenJsonByPath(line, "nodeKey.__SubjectId__");

            if (jsonPaths.Value.GetType() == typeof(List <string>))
            {
                var values = jsonPaths.Value as List <string>;
                values.ForEach(t => Console.WriteLine(t));
            }

            if (jsonPaths.Value.GetType() == typeof(string))
            {
                var value = jsonPaths.Value as string;
                Console.WriteLine(value);
            }
            //jsonPaths.ForEach(t => Console.WriteLine("{0}: {1}", t.Key, t.Value));
        }
예제 #2
0
        /// <summary>
        /// installationid0: 6
        /// installationstatusid0: 4
        /// installationstatus0: FAIL
        /// isactive0: True
        /// installationid1: 7
        /// installationstatusid1: 1
        /// installationstatus1: NEW
        /// isactive1: False
        /// </summary>
        public static void FlattenJson2()
        {
            string line = string.Empty;

            using (var rd = new StreamReader(@".\sampleJson"))
            {
                line = rd.ReadLine();
            }

            var dict = JsonFlatten.Flatten(line, true);

            using (var wr = new StreamWriter(@"D:\E\FlattenedJson2"))
            {
                foreach (var kvp in dict)
                {
                    int    i   = kvp.Key.LastIndexOf(".");
                    string key = (i > -1 ? kvp.Key.Substring(i + 1) : kvp.Key);
                    Match  m   = Regex.Match(kvp.Key, @"\.([0-9]+)\.");
                    if (m.Success)
                    {
                        key += m.Groups[1].Value;
                    }
                    foreach (var value in m.Groups)
                    {
                        var t = value;
                    }
                    Console.WriteLine(key + ": " + kvp.Value);
                    wr.WriteLine(key + ": " + kvp.Value);
                }
            }
        }
예제 #3
0
        public static void FlattenAllJsonPaths()
        {
            string line = string.Empty;

            using (var rd = new StreamReader(@".\sampleJson"))
            {
                line = rd.ReadLine();
            }

            var jsonPaths = JsonFlatten.FlattenAllJsonPaths(line, false);

            jsonPaths.ForEach(t => Console.WriteLine(t));
        }
예제 #4
0
        /// <summary>
        /// installations.installationid: 6
        /// installations.installationstatus.installationstatusid: 4
        /// installations.installationstatus.installationstatus: FAIL
        /// installations.isactive: True
        /// installations.installationid: 7
        /// installations.installationstatus.installationstatusid: 1
        /// installations.installationstatus.installationstatus: NEW
        /// installations.isactive: False
        /// </summary>
        public static void FlattenJsonWithoutArrayIndex()
        {
            string line = string.Empty;

            using (var rd = new StreamReader(@".\sampleJson"))
            {
                line = rd.ReadLine();
            }

            var dict = JsonFlatten.Flatten(line, false);

            using (var wr = new StreamWriter(@"D:\E\FlattenedJsonWithoutArrayIndex"))
            {
                foreach (var kvp in dict)
                {
                    Console.WriteLine(kvp.Key + ": " + kvp.Value);
                    wr.WriteLine(kvp.Key + ": " + kvp.Value);
                }
            }
        }