我在我的应用程序中使用RestSharp。得到回复后我想创建反序列化它。但我只需要这个回复中的一些属性。 响应:
<info>
<product>
<name>MyService</name>
<description>WriteSmthHere</description>
<version>0.0</version>
</product>
<environment>
<currenttime>1970-01-00T00:00:00.000Z</currenttime>
<host>
<address>127.0.0.1</address>
<mac>qwertz123</mac>
<port>1337</port>
</host>
</environment>
<currentsession>
<sessionid>1234567890</sessionid>
<user>mrsmith</user>
<userid>0987654321</userid>
</currentsession>
<configuration>
<externalservices>
<service>
<name>Service1</name>
<address>http://localhost:9999/api/</address>
<timeout>60000</timeout>
</service>
<service>
<name>Service2</name>
<address>http://localhost:9998/api/</address>
<timeout>60000</timeout>
</service>
</externalservices>
</configuration>
型号:
[DataContract]
public class HostInfo
{
[DataMember(Name = "XPath-Here?? maybe 'product.name'")]
public string Host { get; set; }
[DataMember]
public string Port { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Version { get; set; }
}
执行:
JsonDeserializer deserial= new JsonDeserializer();
resultObj = deserial.Deserialize<HostInfo>(response);
有没有办法解决这个问题,而不是改变我的执行代码,或者除了自己解析响应之外别无其他方法了吗?