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);
    }

 

posted @ 2024-01-12 16:26  天天向上518  阅读(84)  评论(0编辑  收藏  举报