我想讓RestSharp與我擁有的寧靜服務一起工作。似乎一切工作正常,除非我的對象通過POST
傳遞包含一個列表(在這種特殊情況下,列表string
)。Rest RestSharp可以在POST請求中發送列表<string>?
我的目標:
public class TestObj
{
public string Name{get;set;}
public List<string> Children{get;set;}
}
當這個被髮送到Children
屬性,都會與內容System.Collections.Generic.List`1[System.String]
字符串發送服務器。
這是怎麼了發送對象:
var client = new RestClient();
var request = new RestRequest("http://localhost", Method.PUT);
var test = new TestObj {Name = "Fred", Children = new List<string> {"Arthur", "Betty"}};
request.AddObject(test);
client.Execute<TestObj>(request);
我做得不對,或者這是RestSharp的錯誤嗎? (如果它有所不同,我使用的是JSON,而不是XML。)
我使用JSON字符串與MVC的ViewModels IEnumerables對於什麼是值得打交道時,所以我不認爲這是一個不好解決的。 –