最近我在codeplex上發(fā)了一個項目SmartObject(基于framework4.5,目前是1.0版本).用法如下:
創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站設(shè)計、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的灤南網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
// 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/