如何通过通用对象解析使用Restsharp?

时间:2018-03-13 11:19:54

标签: c# .net rest restsharp

我的问题与RestSharp的使用有关。我看到很多文档,但我猜有很多版本差异,因为它创造了知识污染。无论如何,我有一个请求和回复。如果您查看下面的示例请求和响应内容,您将看到Employee可以变更,Employee有3个属性,明天它将是具有5个属性的Customer。如何在restsharp中创建或处理?

mycode的:



    class Program
    {
        static void Main(string[] args)
        {

            string body = Resource1.body;
            var client = new RestClient();
            client.BaseUrl = new Uri("http://localhost:8080/kie-server/services/rest/server/containers/instances/RBFFiyatlama2_1.0.1");
            client.Authenticator = new HttpBasicAuthenticator("kieserver", "@test2018");

            var request = new RestRequest();

            request.Method = Method.POST;
            request.AddHeader("Accept", "application/json");
            request.Parameters.Clear();
            request.RequestFormat = DataFormat.Json;
            request.AddBody(new { salary = 1000, cofactor = 1.2, age = 35 });
            var response = client.Execute(request);
            var content = response.Content;
        }
    }

    public class Employee
    {

        public double cofactor { get; set; }
        public double salary { get; set; }
        public int age { get; set; }


    }
}

enter image description here

请求:


{
  "commands": [ 
    {
      "insert": {
        "object": {
       "Employee": {
          "age": 35,  "cofactor" :0.2 , "salary":  2000
      }
        },
        "out-identifier": "t1",
        "return-object": true
      }
    }, 
    {
      "fire-all-rules": ""
    }
  ]
}

响应:


{
   "type": "SUCCESS",
   "msg": "Container RBFFiyatlama2_1.0.1 successfully called.",
   "result": {"execution-results":    {
      "results":       [
                  {
            "value": 1,
            "key": ""
         },
                  {
            "value": {"com.myteam.rbffiyatlama2.Employee":             {
               "salary": 2400,
               "age": 35,
               "cofactor": 0.2
            }},
            "key": "t1"
         }
      ],
      "facts": [      {
         "value": {"org.drools.core.common.DefaultFactHandle": {"external-form": "0:37:1872522807:1872522807:73:DEFAULT:NON_TRAIT:com.myteam.rbffiyatlama2.Employee"}},
         "key": "t1"
      }]
   }}
}

0 个答案:

没有答案