写了几十分钟,现在用不上了,也舍不得扔!
//使用递归将对象序列化成JSON格式字符串
public static String ToJSONString(Menu e)
{
StringBuilder sb = new StringBuilder();
sb.Append("{");
sb.Append("Content:/"" + e.Text + "/",");
sb.Append("Link:/"" + e.Link + "/",");
sb.Append("ChildNodes:[");
Int32 i = 0;
for (; i < e.ChildNodes.Count; ++i)
{
sb.Append(ToJSONString(e.ChildNodes[i]) + ",");
}
if (i > 0)
sb.Remove(sb.Length - 1, 1);
sb.Append("]");
sb.Append("}");
return sb.ToString();
}
//使用递归将对象序列化成JSON格式字符串
public static String ToJSONString(Menu e)
{
StringBuilder sb = new StringBuilder();
sb.Append("{");
sb.Append("Content:/"" + e.Text + "/",");
sb.Append("Link:/"" + e.Link + "/",");
sb.Append("ChildNodes:[");
Int32 i = 0;
for (; i < e.ChildNodes.Count; ++i)
{
sb.Append(ToJSONString(e.ChildNodes[i]) + ",");
}
if (i > 0)
sb.Remove(sb.Length - 1, 1);
sb.Append("]");
sb.Append("}");
return sb.ToString();
}