1 回答
TA贡献1856条经验 获得超11个赞
您提供的代码中存在错误。当它是一个对象时,您正试图将其Properties转换为 a JArray。
如果确实需要Properties对象中的数组,请执行以下操作:
JArray arr = (JArray)result["Items"]["$values"][0]["Properties"]["$values"];
否则,如果您正在寻找Properties对象,那么您应该这样做:
JObject obj = (JObject)result["Items"]["$values"][0]["Properties"];
最后,要重建Customer实例列表,您可以将以下逻辑与静态方法一起使用:
var customersJson = (JArray)result["Items"]["$values"];
var customers = new List<Customer>();
foreach (JObject o in customersJson)
{
var customerJson = (JArray) o["Properties"]["$values"];
customers.Add(BuildCustomer(customerJson));
}
[...]
private static Customer BuildCustomer(JArray a)
{
return new Customer
{
ResultRow = GetValue(a, "ResultRow"),
WorkPhone = GetValue(a, "Work Phone"),
Email = GetValue(a, "Email"),
FullName = GetValue(a, "Full Name"),
iMISId = GetValue(a, "iMISId"),
PreferredPhone = GetValue(a, "Preferred Phone"),
Organization = GetValue(a, "Organization")
};
}
private static string GetValue(JArray array, string name)
{
JToken obj = array.FirstOrDefault(x => (string) x["Name"] == name);
if (obj == null)
return string.Empty;
return (string) obj["Value"];
}
- 1 回答
- 0 关注
- 166 浏览
添加回答
举报