我是C#的新手,我正在尝试使用RestSharp从REST请求中获取JSON响应; 我想要执行的请求如下:"http://myurl.com/api/getCatalog?token=saga001".如果我在浏览器中执行它,它的效果很好.
我试过这个:
var client = new RestClient("http://myurl.com/api/");
var request = new RestRequest("getCatalog?token=saga001");
var queryResult = client.Execute(request);
Console.WriteLine(queryResult);
Run Code Online (Sandbox Code Playgroud)
我得到"RestSharp.RestReponse"而不是我正在跳跃的JSON结果.
谢谢你的帮助 !
我有一个JArray,从文件中读取:
private void RemoveCatalog(Catalog catalog) {
System.IO.StreamReader filereader = new System.IO.StreamReader(@appDirectory + "\\list");
JArray myjarray = JArray.Parse(filereader.ReadToEnd());
filereader.Close();
string json = " {\"token\":\"" + catalog.Token + "\",\"name\":\"" + catalog.Name +"\",\"logo\":\"" + catalog.Logo + "\",\"theme\":\"" + catalog.Theme + "\"}";
JObject myCatalogAsJObject = JObject.Parse(json);
myjarray.Remove(myCatalogAsJObject);
}
Run Code Online (Sandbox Code Playgroud)
我想删除对应于myCatalogAsJObject变量的JObject ,但它不起作用,因为答案myjarray.Contains(myCatalogAsJObject)是假的.
问题是它myjarray实际上包含它:它是我JArray中唯一的JObject.
如果我这样做myCatalogAsJObject.ToString().Equals(myjarray.First.ToString()),答案是正确的.
我被卡住了.