/// <summary> /// 简易JSON格式化输出 /// </summary> /// <param name="strJson"></param> /// <returns></returns> private string formatJson(string strJson) { StringBuilder strNew = new StringBuilder(); string strNewLine = "\r\n"; int tabNum = 0; for (int i = 0; i < strJson.Length; i++) { if (strJson[i] == '{') { strNew.Append(strNewLine); strNew.Append('\t', tabNum); strNew.Append(strJson[i]); tabNum++; strNew.Append(strNewLine); strNew.Append('\t', tabNum); } else if (strJson[i] == '}') { tabNum--; strNew.Append(strNewLine); strNew.Append('\t', tabNum); strNew.Append(strJson[i]); } else if (strJson[i] == ',') { strNew.Append(strJson[i]); strNew.Append(strNewLine); strNew.Append('\t', tabNum); } else { strNew.Append(strJson[i]); } } return strNew.ToString(); }
欢迎转载,转载请注明:转载自[ http://www.cnblogs.com/zjfree/ ]