小工具系列之json查看小工具


無聊寫寫代碼玩玩,仿制firebug的json查看功能寫的小工具,可用於非網頁的JSON查看。

廢話不多說,直接上圖上代碼  DEMO下載

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其實很簡單,如下:

 /// <summary>
        /// 解析
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="list"></param>
        private void Jiexi(object obj, TreeNode node)
        {
            Type type = obj.GetType();
            switch (type.Name)
            {
                case "Dictionary`2": //對象
                    IDictionary<string, object> iDic = (IDictionary<string, object>)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;
            }
        }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM