これから応答が返ってきたら:
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);
}