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()); }
void _writeArray(Array arr, int[] startIdx, int dim, EasyJsonWriter writer) { writer.WriteArrayStart(); for (int i = 0; i < arr.GetLength(dim); ++i) { startIdx[dim] = i; if (dim == arr.Rank - 1) { //writer.WriteJsonValue(base.ObjectToJson(arr.GetValue(startIdx))); writer.WriteValue(arr.GetValue(startIdx)); } else { _writeArray(arr, startIdx, dim + 1, writer); writer.WriteJsonValue(""); } } writer.WriteArrayEnd(); }
public override string ObjectToJson(object obj) { if (obj == null) { return(null); } IList list = obj as IList; EasyJsonWriter writer = new EasyJsonWriter(); writer.WriteArrayStart(); foreach (object element in list) { //writer.WriteJsonValue(base.ObjectToJson(element)); writer.WriteValue(element); } writer.WriteArrayEnd(); return(writer.ToString()); }