SuperMap.Web.ISDotNET6.Entity.ToJson C# (CSharp) Method

ToJson() static private method

static private ToJson ( Entity entity ) : string
entity Entity
return string
        internal static string ToJson(Entity entity)
        {
            if (entity == null)
            {
                return null;
            }
            string json = "{";

            List<string> list = new List<string>();

            if (entity.FieldNames != null && entity.FieldNames.Count > 0)
            {
                List<string> temp = new List<string>();
                foreach (string fn in entity.FieldNames)
                {
                    temp.Add(string.Format("\"{0}\"", fn));
                }
                list.Add(string.Format("\"fieldNames\":[{0}]", string.Join(",", temp.ToArray())));
            }
            else
            {
                list.Add(string.Format("\"fieldNames\":null"));
            }

            if (entity.FieldValues != null && entity.FieldValues.Count > 0)
            {
                List<string> temp = new List<string>();
                foreach (string fv in entity.FieldValues)
                {
                    temp.Add(string.Format("\"{0}\"", fv));
                }
                list.Add(string.Format("\"fieldValues\":[{0}]", string.Join(",", temp.ToArray())));
            }
            else
            {
                list.Add(string.Format("\"fieldValues\":null"));
            }

            list.Add(string.Format("\"shape\":{0}", ServerGeometry.ToJson(entity.Shape)));
            list.Add(string.Format("\"id\":{0}", entity.ID));

            json += string.Join(",", list.ToArray());
            json += "}";
            return json;
        }