c# - Get 方法在使用 C# 的 Restsharp 中不起作用
问题描述
获取方法不起作用...下面的代码使用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"
}
]
}
解决方案
我看到两个问题:
1)“ http://www.jsongenerator.com/api/json/get/cfBwXjwjci?indent=2 ” - 不起作用
2) 如果您提供了正确的 JSON 示例,那么您应该在此处使用“RootObject”:
client.Execute<List<Detail>>(request).Data;
推荐阅读
- c# - 从控制器返回部分视图,在输入中具有正确的 id 和名称
- makefile - 始终处理最外层的文件扩展名(并一路剥离扩展名)
- python - Most Efficient Way to Create Pandas DataFrame from Web Scraped Data
- python - 如果计数大于熊猫中的某个值,如何更改 pd.Series 中的布尔值
- sas - I need to find the confidence intervals for proportions using stratified data
- android - Xamarin : How to deactivate the need for user approval when installing an app
- python - discord.py:我的 discord 机器人有 2 个消息进程。两个中只有一个可以工作,我怎样才能让这两个工作?
- php - Issue in displaying selecting data
- android - Fragment transition with sharedElements stopped working on Anrdoid 9
- c++ - Do I need to deallocate object pointers in a vector?