0
我在RestSharp的內置反序列化中遇到了一些麻煩。RestSharp的反序列化不起作用,C#序列化做
我的代碼:
RestClient client = new RestClient("https://example.com/rest/");
client.ClearHandlers();
client.AddHandler("application/xml", new RestSharp.Deserializers.XmlDeserializer());
var request = new RestRequest();
request.Resource = "member/findScoutIdsForOrganization/{organizationId}";
request.AddUrlSegment("organizationId", orgId);
var response = client.Execute<wsScoutIdList>(request);
var scoutids = response.Data;
XmlSerializer serializer = new XmlSerializer(typeof(wsScoutIdList));
var result = serializer.Deserialize(XmlReader.Create(new StringReader(response.Content)));
wsScoutIdList.java:(由xsd2code產生++)
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.6.81.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute("ScoutIdList", Namespace="", IsNullable=false)]
public partial class wsScoutIdList
{
private List<string> _list;
public wsScoutIdList()
{
this._list = new List<string>();
}
[System.Xml.Serialization.XmlElementAttribute("list", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=true)]
public List<string> list
{
get
{
return this._list;
}
set
{
this._list = value;
}
}
}
XML:
<?xml version ="1.0" encoding="UTF-8" standalone="yes" ?>
<ScoutIdList>
<list>id1</list>
<list>id2</list>
<list>id3</list>
</ScoutIdList>
的System.Xml.Serialization作品,但沒有按RestSharp」噸。該列表簡直是空的。
我也試過json,不工作。
'reque st.RequestFormat = DataFormat.Xml;'不起作用,它使用json然後 'request.AddUrlSegment(「organizationId」,orgId);'是推薦的方法,這沒有什麼錯。 額外的'XmlSerializer'只是爲了表明這個工作正常。 RestSharper方法已經在那裏,並沒有工作。 – filnko