我是 C# 编程的新手,任何帮助都将不胜感激。因为这对于 ac# 开发人员来说可能是一件简单的事情。我尝试了很多东西,但是当我尝试开发它时,Newtonsoft JObjects 中出现了类型不匹配或编译错误。
我有一个对象列表,例如
List<ContextResult> formOutputs ->
[0] = (section 1, Button, true),
[1] = (section 1, TextBox, anyname),
[2] = (section 2, Button, false)
public class ContextResult
{
public string Section { get; set; }
public string Key{ get; set; }
public string Value { get; set; }
}
我需要将其分类,并使用 Newtonsoft.Json.Linq 将其转换为 JObjects 列表。JSON 格式的输出应如下所示,
"section 1":{
"Button": "true",
"TextBox": "anyname"
},
"section 2":{
"Button": "false"
}
请注意,我已经将 formOutputs 排序为升序并使用分组GroupBy
以删除重复项。