超轻量级Json框架SmartObject
最近我在codeplex上发了一个项目SmartObject(基于framework4.5,目前是1.0版本).用法如下:
创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站设计、网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的滦南网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
// HowToUse
using Spider.Data;
//json example fromhttp://www.json.org/example.html
string json1 = @"{""widget"":
{""debug"": ""on"",
""window"":
{""title"": ""Sample Konfabulator Widget""",
""name"": ""main_window"",
""width"": 500,
""height"": 500
},
""p_w_picpath"":
{""src"": ""Images/Sun.png"",
""name"": ""sun1"",
""hOffset"": 250,
""vOffset"": 250,
""alignment"": ""center""},
""text"": {""data"": ""Click Here"",
""size"": 36.23,
""style"": ""bold"",
""name"": ""text1"",
""hOffset"": 250,
""vOffset"": 100,
""alignment"": ""center"", ""onMouseUp"": ""sun1.opacity = (sun1.opacity / 100) * 90;""}
}
}";
string json2 = @"{""menu"":
{ ""id"": ""file"",
""value"": ""File"",
""popup"":
{""menuitem"": [{""value"": ""New"", "" 2},{""value"": ""Open"", "" 1.2},{""value"": ""Close"", "" 55555} ]
}
}
}";
dynamic o1 = SmartObject.Parse(json1);
dynamic o2 = SmartObject.Parse(json2);
Console.WriteLine(o1.widget.text.size);
Console.WriteLine(o1.widget.text[1]); Console.WriteLine(o1.widget.text["size"]);
Console.WriteLine(o1.ToJson());// ToJson return json string
Console.WriteLine(o2.ToJson());
dynamic o3=new SmartObject();
o3.A="abc";
o3["B"]=2345;
Console.WriteLine(o3.IsDefine("C"));
IDictionary
测试运行:
项目地址:http://smartobject.codeplex.com/
文章名称:超轻量级Json框架SmartObject
浏览路径:http://myzitong.com/article/ihdpsc.html