JavaScript中建立JSON物件
var myCats = [
{
"id": 1,
"name": "水果",
"code": "P01",
"lv": ["A", "B", "C"]
},
{
"id": 2,
"name": "蔬菜",
"code": "P02",
"lv": ["A", "A+"]
}
];
.NET 建立JSON字串
JavaScriptSerializer JSS = new JavaScriptSerializer();
Object Obj = new
{
id = 1,
name= "水果",
code= "P01"
}
string JSONString = JSS.Serialize(Obj );
.NET 解析JSON字串成物件
string JSONString = "[\"A\", \"B\",\"C\"]";
List<string> SelGuidList = new JavaScriptSerializer().Deserialize<List<string>>(JSONString );
參考網址:http://blog.roodo.com/syshen/archives/1410294.html
沒有留言:
張貼留言