XmlRpcResponse序列化到c#对象

我是XmlRpc的新手

我写了以下内容:



      XmlRpcRequest requestSearch = new XmlRpcRequest("execute_kw");
        requestSearch.AddParams(db,responseLogin.GetInt(),pass,"hr.attendance","search_read",XmlRpcParameter.AsStruct()
                );

        requestSearch.AddParamStruct(
                     XmlRpcParameter.AsMember("fields",XmlRpcParameter.AsArray("port","ip"))
                );

     XmlRpcResponse responseSearch = client.Execute(requestSearch);
     string result = responseSearch.GetString();

现在我阅读以下字符串:


    [{port: 4370,id: 1,ip: 10.20.1.2},{port: 4370,id: 2,ip:
    10.20.1.3},id: 3,ip: 10.20.1.3}]

如何将其转换为类的对象

 public class Machines
    {
        public int port { get; set; }
        public int id { get; set; }
        public string ip { get; set; }
    }

预先感谢

liuxi5437 回答:XmlRpcResponse序列化到c#对象

您可以使用Newtonsoft将字符串转换为对象。但是IP是字符串类型,应该在引号之间。

string jsonText = "[{port: 4370,id: 1,ip:'10.20.1.2'},{port: 4370,id: 2,ip:'10.20.1.3'},id: 3,ip: '10.20.1.3'}]";
var obj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Machines>>(jsonText);
本文链接:https://www.f2er.com/2978582.html

大家都在问