超轻量级Json框架SmartObject
2013-12-24 09:45
204 查看
最近我在codeplex上发了一个项目SmartObject(基于framework4.5,目前是1.0版本).用法如下: // HowToUse
using Spider.Data;
//json example from http://www.json.org/example.html
string json1 = @"{""widget"":
{""debug"": ""on"",
""window"":
{""title"": ""Sample Konfabulator Widget""",
""name"": ""main_window"",
""width"": 500,
""height"": 500
},
""image"":
{""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<string, object> dict=o3.AsDictionary();
测试运行:
项目地址:http://smartobject.codeplex.com/
using Spider.Data;
//json example from http://www.json.org/example.html
string json1 = @"{""widget"":
{""debug"": ""on"",
""window"":
{""title"": ""Sample Konfabulator Widget""",
""name"": ""main_window"",
""width"": 500,
""height"": 500
},
""image"":
{""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<string, object> dict=o3.AsDictionary();
测试运行:
项目地址:http://smartobject.codeplex.com/
相关文章推荐
- 超轻量级Json框架SmartObject
- Json-smart实现JSONObject、JSONString、Beans之间的转换
- Jackson框架的JsonGenerator、ObjectMapper - Json-lib框架的JsonObject、JsonArray
- 凭借K2 SmartObject框架,在SharePoint中集成数据
- Jackson框架提供的JsonGenerator ObjectMapper以及JSONObject 、JSONArray学习
- Android-Volley网络通信框架(StringRequest & JsonObjectRequest)
- Jackson框架提供的JsonGenerator ObjectMapper以及JSONObject 、JSONArray学习
- Jackson框架提供的JsonGenerator ObjectMapper以及JSONObject 、JSONArray学习
- Android-Volley网络通信框架(StringRequest和JsonObjectRequset)
- easyui框架Date日期类型以json形式显示到前台datagrid时,显示为[object Object]
- Volley框架网络访问String,JsonObject,JsonArray
- 基于Web Service的客户端框架搭建一:C#使用Http Post方式传递Json数据字符串调用Web Service
- Android智能下拉刷新框架-SmartRefreshLayout
- 前端开发学习二——由JSON和Object Literal Notation引起的思考
- json&jsonArray&gson&list&List<Map<String,Object>>&listview&adapter
- java json字符串转JSONObject和JSONArray以及取值
- fastjson --JSONObject 和JSONArray 转换
- SuperObject的JSON使用方法
- [JSON-lib框架]使java对象、json、xml之间的转换不再困难
- JavaScript Object Notation (JSON)