OneNote Json对象丢失

时间:2018-01-17 17:02:41

标签: json microsoft-graph onenote-api

当我使用MS Graph OneNote API使用GetAllSections调用时,我得到“ID”对象但不是“Name”对象。

我的ApiBaseResponse类和GenericEntityResponse类是MS docs的标准,没有任何更改。

以下是我的代码:

 private async void GetSectionsButton_Click(object sender, RoutedEventArgs e)
    {

        //   private string apiSectionsRoute = "https://graph.microsoft.com/v1.0/me/onenote/sections";
             string tempStr = await GetAllSections(apiSectionsRoute);
    }



    public async Task<String> GetAllSections(string apisectionsroute)
    {
        var client = new HttpClient();

        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken);

        var createMessage = new HttpRequestMessage(HttpMethod.Get, apisectionsroute);

        HttpResponseMessage response = await client.SendAsync(createMessage);

        var apiBaseResponse = new List<ApiBaseResponse>();
        string body = await response.Content.ReadAsStringAsync();
        if (response.StatusCode == HttpStatusCode.OK)
        {
            var content = JObject.Parse(body);
            apiBaseResponse = new List<ApiBaseResponse>(JsonConvert.DeserializeObject<List<GenericEntityResponse>>(content["value"].ToString()));
        }
        if (apiBaseResponse.Count == 0)
        {
            apiBaseResponse.Add(new ApiBaseResponse());
        }

        IEnumerable<string> correlationValues;
        if (response.Headers.TryGetValues("X-CorrelationId", out correlationValues))
        {
            apiBaseResponse[0].CorrelationId = correlationValues.FirstOrDefault();
        }
        apiBaseResponse[0].StatusCode = response.StatusCode;
        apiBaseResponse[0].Body = body;


        return apiBaseResponse[0].Body.ToString();


    }

我希望每个部分都能看到“名称:xxxx,ID:xxxxx”。 现在,我只收到身份证。

完整性,下面是ApiBaseResponse和GenericEntityResponse:

public class ApiBaseResponse
{
    /// <summary>
    /// All OneNote API reponses return a meaningful Http status code
    /// Typical pattern for Http status codes are used: 
    /// 1 1xx Informational
    /// 2 2xx Success. e.g. 200-OK for GETs, 201 -Created for POSTs
    /// 3 3xx Redirection
    /// 4 4xx Client Error e.g. 400-Bad Request
    /// 5 5xx Server Error e.g. 500-Internal Server Error
    /// </summary>
    public HttpStatusCode StatusCode { get; set; }

    /// <summary>
    /// Per call identifier that can be logged to diagnose issues with Microsoft support
    /// CorrelationId is included in all Response Headers
    /// </summary>
    public string CorrelationId { get; set; }

    /// <summary>
    /// Body of the OneNote API response represented as a string.
    /// For error cases, this will typically include an error json intended for developers, not for end users.
    /// For success cases, depending on the type API call/HTTP verb this may or may not include a json value
    /// </summary>
    public string Body { get; set; }

    /// <summary>
    /// URLs to launch OneNote rich client/web app
    /// </summary>
    public Links Links { get; set; }

    /// <summary>
    /// Unique identifier of the object
    /// </summary>
    public string Id { get; set; }

}

public class Links
{
    /// <summary>
    /// URL to launch OneNote rich client
    /// </summary>
    public HrefUrl OneNoteClientUrl { get; set; }

    /// <summary>
    /// URL to launch OneNote web experience
    /// </summary>
    public HrefUrl OneNoteWebUrl { get; set; }
}

public class HrefUrl
{
    public string Href { get; set; }
}


public class GenericEntityResponse : ApiBaseResponse
{
    /// <summary>
    /// Name of the entity
    /// </summary>
    public string Name;

    /// <summary>
    /// Self link to the given entity
    /// </summary>
    public string Self { get; set; }

    public List<GenericEntityResponse> Sections { get; set; }

    public List<GenericEntityResponse> SectionGroups { get; set; }

    public override string ToString()
    {
        return "Name: " + Name + ", Id: " + Id;
    }
}

1 个答案:

答案 0 :(得分:0)

该属性被称为&#34; displayName&#34;,而不是&#34; name&#34;。