Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder("{ ");
- ToString(sb);
- sb.Append("}");
- return sb.ToString();
- }
- private void ToString(StringBuilder sb)
- {
- bool firstDict = true;
- foreach (var pair in _dictionary)
- {
- if (!firstDict)
- sb.Append(",");
- firstDict = false;
- sb.Append("\"" + pair.Key + "\": ");
- if (pair.Value is string)
- {
- sb.Append("\"" + pair.Value.ToString() + "\"");
- }
- else if (pair.Value is Dictionary<string, object>)
- {
- sb.Append((new DynamicJsonObject(pair.Value as Dictionary<string, object>).ToString()));
- }
- else if (pair.Value is ArrayList)
- {
- if((pair.Value as ArrayList).Count > 1)
- sb.Append("[");
- bool firstAL = true;
- foreach (var item in pair.Value as ArrayList)
- {
- if (!firstAL)
- sb.Append(",");
- firstAL = false;
- if (item is string)
- sb.Append("\"" + item + "\"");
- else if (item is IDictionary<string, object>)
- sb.Append((new DynamicJsonObject(item as Dictionary<string, object>).ToString()));
- else
- {
- sb.Append("ERROR");
- }
- }
- if ((pair.Value as ArrayList).Count > 1)
- sb.Append("]");
- }
- else
- {
- sb.Append("ERROR");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement