当我收到我的回复时:
public IEnumerable<Organisation> GetAll()
{
string requestUrl = BlaBla.APIURL + "/org/";
//string response = await postRequest.AuthenticatedGetData(requestUrl, BlablaDataContext.Contract.AccessToken).Result;
AuthenticatedGetData(requestUrl, BlaBla.Contract.AccessToken);
IEnumerable<Organisation> organisations = new Organisation[] {};
return organisations;
}
public override void WebClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
string response = e.Result;
using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(response)))
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Contract));
Contract contract = (Contract)serializer.ReadObject(stream);
}
}
...
string response = e.Result();
正在返回以下内容:
response"[{\"status\":\"active\",\"segment\":null,\"contract_status\":\"none\",\"name\":\"Projects with James\",\"rights\...
我如何阻止这种情况发生,因为我无法使用http://json2csharp.com/将我的 json 转换为 csharp 对象...
我的网络客户端看起来像这样:
abstract public class PostRequest
{
public void AuthenticatedGetData(string url, string accessToken)
{
WebClient client = new WebClient();
//client.Headers["Content-Type"] = "application/json";
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(this.WebClient_DownloadStringCompleted);
client.DownloadStringAsync(new Uri(url + "?oauth_token=" + accessToken));
}
public abstract void WebClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e);
}