Dynamic简单使用获取表值或者json数据
注意点,要先赋值给左侧,
public async Task<ResponseResult<dynamic>> doTest() { string sqlStr = @"select ""JabilPn"" from public.""Eme_Materials"" limit 1"; var data = await DbScoped.SugarScope.Ado.SqlQuerySingleAsync<dynamic>(sqlStr); // string getjson = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(data.ToString()); string getv = data.JabilPn; //--这里需要先赋值给左侧即可,直接打印不出来的 return ResponseResult<dynamic>.Success(data: data); }
public async Task<ResponseResult<dynamic>> doTest() { //string sqlStr = @"select ""Id"",""JabilPn"" from public.""Eme_Materials"" limit 1"; string sqljsonStr = @"select ""id"",""jsonv"" from public.test00001"; var data = await DbScoped.SugarScope.Ado.SqlQuerySingleAsync<dynamic>(sqljsonStr); // string getjson = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(data.ToString()); string getv = data.jsonv; //--这里需要先赋值给左侧即可,直接打印不出来的 dynamic getv2 = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(getv); string getjsonName = getv2.name; return ResponseResult<dynamic>.Success(data: data); }
如有疑问或者错误的地方,请跟帖,本人会第一时间答复以及相互学习,谢谢!个人会不断的上传自己的学习心得!
好了今天就先到这里,下次有时间再更新,如果存在不合理的地方,欢迎大家多多指教留言!!!