【问题标题】:XmlNodeConverter can only convert JSON that begins with an object. Path '', line 1, position 1XmlNodeConverter 只能转换以对象开头的 JSON。路径'',第 1 行,位置 1
【发布时间】:2019-09-18 10:10:59
【问题描述】:

遇到以下代码问题

System.Xml.XmlDocument xd1 = new System.Xml.XmlDocument();
xd1 = (System.Xml.XmlDocument)Newtonsoft.Json.JsonConvert.DeserializeXmlNode(customJsonArrayData.ToString(), currentSheetName); //getting issue here.
DataSet jsonDataSet = new DataSet();
jsonDataSet.ReadXml(new System.Xml.XmlNodeReader(xd1));

我已经查看了link,但我们是否有比该帖子中给出的任何简短的答案。

【问题讨论】:

  • 该解决方案在您的项目中有效吗?如果无效,您能分享一下customJsonArrayData.ToString()currentSheetName吗?

标签: c# asp.net asp.net-core


【解决方案1】:

对于 XmlNodeConverter 只能转换以对象开头的 JSON,您可以手动添加对象,如下所示:

xd1 = (System.Xml.XmlDocument)Newtonsoft.Json.JsonConvert.DeserializeXmlNode("{\"root \":"+yourJsonString+"}","root");

【讨论】:

    猜你喜欢
    • 2018-07-24
    • 1970-01-01
    • 2020-07-04
    • 2020-12-15
    • 1970-01-01
    • 1970-01-01
    • 2019-12-31
    • 2021-03-18
    • 1970-01-01
    相关资源
    最近更新 更多