【问题标题】:Get method is not working in Restsharp using C#Get 方法在使用 C# 的 Restsharp 中不起作用
【发布时间】:2019-05-28 05:13:01
【问题描述】:

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

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"
    }
  ]
}

【问题讨论】:

  • 状态码是什么
  • 什么都不显示
  • 什么意思不显示,当然有

标签: c# json rest restsharp


【解决方案1】:

我看到两个问题:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-18
    • 1970-01-01
    相关资源
    最近更新 更多