UnboundLocalError: local variable 'var1' referenced before assignment
这是我的JSON格式。如何在C#中转换为ExpandoObject? 这是我的代码,
{
"Jhone":[
{
"Key":"Employeename",
"Value":"Jhone"
},
{
"Key":"Address",
"Value":[
{
"Key":"City",
"Value":"Newyork"
},
{
"Key":"Country",
"Value":"USA"
}
]
}
],
"Mohamed":[
{
"Key":"Employeename",
"Value":"Mohamed"
},
{
"Key":"Address",
"Value":[
{
"Key":"City",
"Value":"Delhi"
},
{
"Key":"Country",
"Value":"india"
}
]
}
]
}
答案 0 :(得分:0)
也许您可以使用此扩展方法
public static ExpandoObject Expando(this IEnumerable<KeyValuePair<string, object>> dictionary)
{
var expando = new ExpandoObject();
var expandoDic = (IDictionary<string, object>)expando;
foreach (var item in dictionary)
{
expandoDic.Add(item);
}
return expando;
}
方法返回带有键,值列表的ExpandoObject