C#接收webservice返回的xml 进行反序列化操作报错

public static T Deserialize<T>(string xml)
        {
            using (StringReader sr = new StringReader(xml))
            //TextReader reader = new StreamReader(xml);
            {
                XmlSerializer xmldes = new XmlSerializer(typeof(T));
                 T r = (T)xmldes.Deserialize(sr);
                //var r = xmldes.Deserialize(reader);
                return (T)r;
            }
        }

将呼叫webservice返回的xml传入此方法中  xml可视化后如下

<?xml version="1.0" encoding="UTF-8"?>

-<Ingredients wipEntity="14396595" macCode="CC180565-1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<item timeStamp="2021-06-03 15:03:20" tagValue="14396595" tagCode="CC180565-1_1000"/>

<item timeStamp="2021-06-03 15:03:20" tagValue="101293905-102" tagCode="CC180565-1_1002"/>

<item timeStamp="2021-06-03 15:03:20" tagValue="CM1" tagCode="CC180565-1_1001"/>

<item timeStamp="2021-06-03 15:03:20" tagValue="72" tagCode="CC180565-1_1003"/>

<item timeStamp="2021-06-03 15:03:20" tagValue="150" tagCode="CC180565-1_CC180565-1_1004"/>

<item timeStamp="2021-06-03 15:03:20" tagValue="150" tagCode="CC180565-1_CC180565-2_1004"/>

<item timeStamp="2021-06-03 15:03:20" tagValue="30" tagCode="CC180565-1_CC180565-1_1005"/>

<item timeStamp="2021-06-03 15:03:20" tagValue="30" tagCode="CC180565-1_CC180565-2_1005"/>

</Ingredients>

但是反序列报错

System.InvalidOperationException:“XML 文档(1, 1)中有错误。”

 

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^