使用C#在Restsharp中获取方法不起作用

时间:2019-05-28 05:13:01

标签: c# json rest restsharp

获取方法不起作用...下面的代码使用restsharp在json中的Richtext框中显示所有名称或其他属性...没有错误,但是Ouput没有来帮助我解决这个问题...

var client = new RestClient("http://www.jsongenerator.com/api/json/get/cfBwXjwjci?indent=2");
var request = new RestRequest(Method.GET);
var queryResult = client.Execute<List<Detail>>(request).Data;
foreach (var rl in queryResult)
     {
        richTextBox1.Text = rl.name;
     }

public class Detail
    {
        public string city { get; set; }
        public int id { get; set; }
        public string Blood { get; set; }
        public string name { get; set; }
    }

这里是json

{
  "Details": [
    {
      "city": "Londan", 
      "id": 1, 
      "Blood": "O+", 
      "name": "Nicolas"
    }, 
    {
      "city": "USA", 
      "id": 2, 
      "Blood": "A+", 
      "name": "Jhon"
    }, 
    {
      "city": "India", 
      "id": 3, 
      "Blood": "B-", 
      "name": "Shiva"
    }
  ]
}

1 个答案:

答案 0 :(得分:0)

我看到两个问题:

1)“ http://www.jsongenerator.com/api/json/get/cfBwXjwjci?indent=2”-不起作用

2)如果提供了正确的JSON示例,则应在此处使用“ RootObject”:

client.Execute<List<Detail>>(request).Data;