C#中处理JSON字符串和对象的简单方法:
dynamic json = System.Web.Helpers.Json.Decode(JSON_STRING);
value = json["name"] ?? DEFAULT_VALUE;
也可以直接用
value = json.name
如果要生成JSON字符串,可以直接把对象用
class YourClass {
public string Key1;
public string Key2;
public int Key3;
// etc ....
}
YourClass obj = new YourClass();
obj.Key1 = "abc";
obj.Key2 = "def";
obj.Key3 = 0;
string jsonstr = System.Web.Helpers.Json.Encode(obj);