无聊写写代码玩玩,仿制firebug的json查看功能写的小工具,可用于非网页的JSON查看。
废话不多说,直接上图上代码
json代码
[{"PID":1,"PName":"向城轩","AttentionCount":4,"Score":0,"Address":"上海市浦东新区茂兴路","proList":[],"PointX":13523723.5655,"PointY":3663540.2966,"IsProduct":false},{"PID":2,"PName":"韵泓筷子店","AttentionCount":1,"Score":0,"Address":"","proList":[],"PointX":13522930.5099,"PointY":3663762.6306,"IsProduct":false},{"PID":3,"PName":"家化中房苑","AttentionCount":1,"Score":0,"Address":"","proList":[],"PointX":13521716.2099,"PointY":3664131.6649,"IsProduct":false},{"PID":4,"PName":"上海沈工机电供应站","AttentionCount":1,"Score":0,"Address":"","proList":[],"PointX":13522749.0207,"PointY":3664046.4908,"IsProduct":false},{"PID":5,"PName":"上海张小泉刀剪总店","AttentionCount":0,"Score":0,"Address":"","proList":[],"PointX":13522694.1534,"PointY":3663716.4823,"IsProduct":false},{"PID":6,"PName":"培罗蒙","AttentionCount":0,"Score":0,"Address":"","proList":[],"PointX":13522644.7967,"PointY":3663838.1673,"IsProduct":false},{"PID":7,"PName":"停车场","AttentionCount":0,"Score":0,"Address":"","proList":[],"PointX":13523709.1033,"PointY":3663547.5709,"IsProduct":false},{"PID":8,"PName":"盘谷银行","AttentionCount":0,"Score":0,"Address":"","proList":[],"PointX":13523752.4223,"PointY":3663571.1879,"IsProduct":false},{"PID":9,"PName":"中国工商银行","AttentionCount":0,"Score":0,"Address":"","proList":[],"PointX":13523666.2735,"PointY":3663595.213,"IsProduct":false},{"PID":10,"PName":"广发银行","AttentionCount":0,"Score":0,"Address":"","proList":[],"PointX":13523043.7535,"PointY":3663513.642,"IsProduct":false},{"PID":11,"PName":"申华金融大厦","AttentionCount":0,"Score":0,"Address":"","proList":[],"PointX":13523352.434,"PointY":3664158.9574,"IsProduct":false},{"PID":12,"PName":"德兴馆","AttentionCount":6,"Score":0,"Address":"","proList":[],"PointX":13522483.4045,"PointY":3664060.1596,"IsProduct":false},{"PID":13,"PName":"福丹机电","AttentionCount":0,"Score":0,"Address":"","proList":[],"PointX":13522451.553,"PointY":3664067.2636,"IsProduct":false},{"PID":14,"PName":"上海同缘烟草烟酒专卖","AttentionCount":0,"Score":0,"Address":"","proList":[],"PointX":13522613.0783,"PointY":3663763.9579,"IsProduct":false},{"PID":15,"PName":"老客了酒楼","AttentionCount":1,"Score":0,"Address":"","proList":[],"PointX":13522609.7829,"PointY":3663775.1921,"IsProduct":false},{"PID":16,"PName":"虹庙旧木器商店","AttentionCount":0,"Score":0,"Address":"","proList":[],"PointX":13522601.8907,"PointY":3663801.5225,"IsProduct":false},{"PID":17,"PName":"上海长江企业发展合租公司","AttentionCount":0,"Score":0,"Address":"","proList":[],"PointX":13522602.1667,"PointY":3663814.223,"IsProduct":false},{"PID":18,"PName":"中国旅行社总社","AttentionCount":0,"Score":0,"Address":"","proList":[],"PointX":13522605.4669,"PointY":3663827.1539,"IsProduct":false},{"PID":19,"PName":"BaleNo","AttentionCount":0,"Score":0,"Address":"","proList":[],"PointX":13522578.4438,"PointY":3663680.5367,"IsProduct":false},{"PID":20,"PName":"NOKIA","AttentionCount":0,"Score":0,"Address":"","proList":[],"PointX":13522591.8576,"PointY":3663682.989,"IsProduct":false}]
[1,2,3,["a","b","c",["A","B","C"]]]
code其实很简单,如下:
////// 解析 /// /// /// private void Jiexi(object obj, TreeNode node) { Type type = obj.GetType(); switch (type.Name) { case "Dictionary`2": //对象 IDictionaryiDic = (IDictionary )obj; node.Text += "(Object){ "; int c = 0; foreach (var o in iDic) { if (o.Value.GetType().Name != "Object[]" && c<3) { node.Text += o.ToString() + ","; } TreeNode t = new TreeNode(o.Key + ": "); node.Nodes.Add(t); Jiexi(o.Value, t); c++; } node.Text += "...}"; break; case "Object[]": //数组 IList ilist = (IList)obj; int i = 0; if (ilist == null || ilist.Count == 0) node.Text += " []"; foreach (var o in ilist) { TreeNode t = new TreeNode(i.ToString()); node.Nodes.Add(t); Jiexi(o, t); i++; } break; default: node.Text += "(" + type.Name + ")" + obj.ToString(); break; } }