标签:color ext unit div pre var 修改 blog turn
修改texturepacker生成的json串之后,对其进行格式化,相关代码:
public static string JsonTree(string json) { int level = 0; var jsonArr = json.ToArray(); string jsonTree = string.Empty; for (int i = 0; i < json.Length; i++) { char c = jsonArr[i]; if (level > 0 && ‘\n‘ == jsonTree.ToArray()[jsonTree.Length - 1]) { jsonTree += TreeLevel(level); } switch (c) { case ‘{‘: jsonTree += c + "\n"; level++; break; case ‘,‘: jsonTree += c + "\n"; break; case ‘}‘: jsonTree += "\n"; level--; jsonTree += TreeLevel(level); jsonTree += c; break; default: jsonTree += c; break; } } return jsonTree; } private static string TreeLevel(int level) { string leaf = string.Empty; for (int t = 0; t < level; t++) { leaf += "\t"; } return leaf; }
标签:color ext unit div pre var 修改 blog turn
原文地址:http://www.cnblogs.com/Yellow0-0River/p/7574208.html