【发布时间】:2018-01-24 22:32:03
【问题描述】:
我的客户正在向我发送这样的对象:
"content": {
"title": "data title",
"values": {
"25": "some description",
"26": "some info",
"27": "some text",
"28": "some other data",
"29": "more info",
"30": "more text",
"31": "and another more description"
}
}
我需要将 values 保存在 C# List<> 对象上。
我正在尝试像这样获取和保存这些值:
public static List<MyKeyValuePair> GetClientValues(dynamic content)
{
var myList = new List<MyKeyValuePair>();
try
{
foreach (PropertyInfo pi in content.values.GetType().GetProperties())
{
var value = "";
myList.Add(new MyKeyValuePair() { Id = int.Parse(pi.Name), Description = pi.GetValue(value, null).ToString() });
}
}
catch { }
return myList;
}
但是在foreach 行我收到了这个错误信息:
'System.Collections.Generic.Dictionary.values' 是 由于其保护级别而无法访问
我该如何解决这个问题?
【问题讨论】:
标签: javascript c# json parsing dynamic