如何从动态Object按索引检索值

时间:2016-01-15 20:20:22

标签: xelement dynamicobject

multiprocessing
  

我想检索动态索引值。我用过新的

     

XElement(“FL”,新XAttribute(“val”,“Title”),   jsonObj.GetType()的getProperty( “标题”)。的GetValue(jsonObj,NULL))   但是我仍然在通过索引

检索值时遇到异常

1 个答案:

答案 0 :(得分:0)

jsonObj是一个数组,所以你需要先查询数组中的第一个元素,然后再查询json文字。

dynamic jsonObj = JsonConvert.DeserializeObject(zohoResponse);
dynamic arr = jsonObj.First;

var xmlData = new XDocument(
                    new XElement("Leads",
                            new XElement("row", new XAttribute("no", "1"),
                            new XElement("FL", new XAttribute("val", "Lead Source"), arr["Last Name"]),
                        new XElement("FL", new XAttribute("val", "Title"), arr["First Name"])
                    )));