C# xml字符串序列化为对象时,提示:{"名称中不能包含“=”字符(十六进制值 0x3D)
C#xml字符串序列化为对象时,提示:{"名称中不能包含“=”字符(十六进制值0x3D)。第1行,位置64。"},大神帮我看看字符串哪里有问题我贴源代码:postInfo...
C# xml字符串序列化为对象时,提示:{"名称中不能包含“=”字符(十六进制值 0x3D)。 第 1 行,位置 64。"},大神帮我看看 字符串哪里有问题我贴源代码:
postInfoBaseModel obj = XmlDeserialize<postInfoBaseModel>(result);
public static T XmlDeserialize<T>(string xmlString)
{
string test = "<?xml version=\"1.0\" encoding=\"UTF - 8\"?><postInfoBaseModelxmlns=\"http://tempuri.org/\"xmlns:xsd=\"http://www.w3.org/2001/XMLSchemaxmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><status>503</status><message>1121</message></postInfoBaseModel>";
T t = default(T);
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
using (StringReader stringReader = new StringReader(test))
{
Object obj = xmlSerializer.Deserialize(stringReader);
t = (T)obj;
}
return t;
}
//类定义
[Serializable]
public class postInfoBaseModel
{
[XmlElement("status")]
public int status { get; set; }
[XmlElement("message")]
public string message { get; set; }
} 展开
postInfoBaseModel obj = XmlDeserialize<postInfoBaseModel>(result);
public static T XmlDeserialize<T>(string xmlString)
{
string test = "<?xml version=\"1.0\" encoding=\"UTF - 8\"?><postInfoBaseModelxmlns=\"http://tempuri.org/\"xmlns:xsd=\"http://www.w3.org/2001/XMLSchemaxmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><status>503</status><message>1121</message></postInfoBaseModel>";
T t = default(T);
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
using (StringReader stringReader = new StringReader(test))
{
Object obj = xmlSerializer.Deserialize(stringReader);
t = (T)obj;
}
return t;
}
//类定义
[Serializable]
public class postInfoBaseModel
{
[XmlElement("status")]
public int status { get; set; }
[XmlElement("message")]
public string message { get; set; }
} 展开
1个回答
展开全部
你仔细看下
<?xml version="1.0" encoding="UTF - 8"?>
<postInfoBaseModelxmlns="http://tempuri.org/"xmlns:xsd="http://www.w3.org/2001/XMLSchemaxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<status>503</status>
<message>1121</message>
</postInfoBaseModel>
这样格式化就清楚了,
postInfoBaseModelxmlns=
中间少了一个空格,而且后面都少了很多空格,并且不要用输入法写代码,utf-8这里也错了,应该这样才对
<?xml version="1.0" encoding="UTF-8"?>
<postInfoBaseModel xmlns="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<status>503</status>
<message>1121</message>
</postInfoBaseModel>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询