0

当我收到我的回复时:

    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);
}
4

2 回答 2

3

您确定字符串中实际上有反斜杠,而不是 Visual Studio 的可视化工具吗?如果你将结果输出到一个文件中,它是什么样子的?

赠品是字符串以"...开头

于 2013-10-01T00:12:57.543 回答
0

我的朋友,反斜杠出现是因为您将其转换为字符串!使用: http: //james.newtonking.com/json它是 WP 最好的(在我看来)Json 库。它非常易于使用并且具有强大的功能。

于 2013-10-01T09:44:02.787 回答