c#转换字典<;字符串,列表<&燃气轮机&燃气轮机;到字典<;字符串,对象>;

c#转换字典<;字符串,列表<&燃气轮机&燃气轮机;到字典<;字符串,对象>;,c#,dictionary,casting,C#,Dictionary,Casting,如何以c#(linq)方式将字符串附加到Json输出 //字典 var res=结果,其中(x=>x.ConfidenceScore>0) .GroupBy(x=>x.PropertyName) .ToDictionary(g=>g.Key, g=>g.Select(x=>x.Value.ToString()).ToList() ); >>> ??? res[“OcrText”]=文档文本; Console.Out.WriteLine(JsonConvert.SerializeObject(r

如何以c#(linq)方式将字符串附加到Json输出

//字典
var res=结果,其中(x=>x.ConfidenceScore>0)
.GroupBy(x=>x.PropertyName)
.ToDictionary(g=>g.Key,
g=>g.Select(x=>x.Value.ToString()).ToList()
); 
>>> ??? res[“OcrText”]=文档文本;
Console.Out.WriteLine(JsonConvert.SerializeObject(res));
目前,我必须将整个字典复制到另一个be元素以转换类型

Dictionary<string, object> ugly = new Dictionary<string, object>();

foreach (var item in res)
{
  ugly.Add(item.Key, item.Value);
}
ugly["OcrText"] = doc.Text;
Dictionary=newdictionary();
foreach(资源中的var项目)
{
添加(item.Key,item.Value);
}
丑陋的[“OcrText”]=文档文本;

如果我理解正确,您只想将
字典
转换为
字典()

你可以用

然而,你为什么要这样做还有争议

或者你想

var res = results.Where(x => x.ConfidenceScore > 0)
               .GroupBy(x => x.PropertyName)
               .ToDictionary(g => g.Key,
                  g => (object)g.Select(x => x.Value.ToString()).ToList()
               );

尽管这样说,我还是被这个问题弄糊涂了,我想如果我理解正确,你只想把
字典
转换成
字典()

你可以用

然而,你为什么要这样做还有争议

或者你想

var res = results.Where(x => x.ConfidenceScore > 0)
               .GroupBy(x => x.PropertyName)
               .ToDictionary(g => g.Key,
                  g => (object)g.Select(x => x.Value.ToString()).ToList()
               );
尽管这么说,我还是被这个问题弄糊涂了,我认为你需要进一步澄清

var res = results.Where(x => x.ConfidenceScore > 0)
               .GroupBy(x => x.PropertyName)
               .ToDictionary(g => g.Key,
                  g => (object)g.Select(x => x.Value.ToString()).ToList()
               );