Example #1
0
        /// <summary>
        /// Writes row as JSON either as an array or map depending on JSONWritingOptions.RowsAsMap setting.
        /// Do not call this method directly, instead call rowset.ToJSON() or use JSONWriter class
        /// </summary>
        public void WriteAsJSON(System.IO.TextWriter wri, int nestingLevel, JSONWritingOptions options = null)
        {
            if (options == null || !options.RowsAsMap)
            {
                JSONWriter.WriteArray(wri, this, nestingLevel, options);
                return;
            }

            var map = new Dictionary <string, object>();

            foreach (var fd in Schema)
            {
                map.Add(fd.Name, GetFieldValue(fd));
            }

            if (this is IAmorphousData)
            {
                var amorph = (IAmorphousData)this;
                if (amorph.AmorphousDataEnabled)
                {
                    foreach (var kv in amorph.AmorphousData)
                    {
                        var key = kv.Key;
                        while (map.ContainsKey(key))
                        {
                            key += "_";
                        }
                        map.Add(key, kv.Value);
                    }
                }
            }

            JSONWriter.WriteMap(wri, map, nestingLevel, options);
        }
Example #2
0
File: Row.cs Project: zhabis/nfx
        /// <summary>
        /// Writes row as JSON either as an array or map depending on JSONWritingOptions.RowsAsMap setting.
        /// Do not call this method directly, instead call rowset.ToJSON() or use JSONWriter class
        /// </summary>
        public void WriteAsJSON(System.IO.TextWriter wri, int nestingLevel, JSONWritingOptions options = null)
        {
            if (options == null || !options.RowsAsMap)
            {
                JSONWriter.WriteArray(wri, this, nestingLevel, options);
                return;
            }

            var map = new Dictionary <string, object>();

            foreach (var fd in Schema)
            {
                string name;

                var val = FilterJSONSerializerField(fd, options, out name);
                if (name.IsNullOrWhiteSpace())
                {
                    continue;
                }

                map[name] = val;
            }

            if (this is IAmorphousData)
            {
                var amorph = (IAmorphousData)this;
                if (amorph.AmorphousDataEnabled)
                {
                    foreach (var kv in amorph.AmorphousData)
                    {
                        var key = kv.Key;
                        while (map.ContainsKey(key))
                        {
                            key += "_";
                        }
                        map.Add(key, kv.Value);
                    }
                }
            }

            JSONWriter.WriteMap(wri, map, nestingLevel, options);
        }