public override string ObjectToJson(object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            IDictionary      dict         = obj as IDictionary;
            EasyJsonWriter   writer       = new EasyJsonWriter();
            JsonItemMetadata itemMetadata = _getItemMetadata(obj.GetType());

            ObjectToJsonFunc keyFunc = _stringKeyToJsonName;

            if (itemMetadata.IndexType != typeof(string))
            {
                keyFunc = base.ObjectToJson;
            }

            writer.WriteObjectStart();
            foreach (DictionaryEntry entry in dict)
            {
                writer.WriteName(JsonUtil.Escape(keyFunc(entry.Key)));
                //writer.WriteJsonValue(base.ObjectToJson(entry.Value));
                writer.WriteValue(entry.Value);
            }
            writer.WriteObjectEnd();

            return(writer.ToString());
        }
Exemple #2
0
        public override string ToString()
        {
            if (Type == EasyJsonDataType.JsonObject)
            {
                EasyJsonWriter writer = new EasyJsonWriter();
                writer.WriteObjectStart();
                foreach (string name in Names)
                {
                    writer.WriteName(name);
                    writer.WriteJsonValue(this[name].ToString());
                }
                writer.WriteObjectEnd();

                return(writer.ToString());
            }
            else if (Type == EasyJsonDataType.JsonArray)
            {
                EasyJsonWriter writer = new EasyJsonWriter();
                writer.WriteArrayStart();
                for (int i = 0; i < Count; ++i)
                {
                    writer.WriteJsonValue(this[i].ToString());
                }
                writer.WriteArrayEnd();

                return(writer.ToString());
            }
            else if (Type == EasyJsonDataType.JsonString)
            {
                return(JsonUtil.STRING_QUOTE + Data + JsonUtil.STRING_QUOTE);
            }
            else
            {
                return(Data);
            }
        }
Exemple #3
0
 void _writeObject(string name, object value, EasyJsonWriter writer)
 {
     writer.WriteName(name);
     _writeObject(value, writer);
 }