public object AnonymousObj()
{
return new { UserId = "", Message = "OK", Data = new {...} }
} public void Other()
{
var obj = AnonymousObj();
string data = obj.GetType().GetProperty("Data").GetValue(obj).ToString(); }
运用了C#反射
针对Json字符串可以使用如下方法:
var res = JsonConvert.DeserializeObject<dynamic>(jsonStr);
string code = res.code;
……