Объект OneNote Json отсутствует

Я получаю объект "ID", но не объект "Name", когда я использую вызов GetAllSections с помощью API-интерфейса MS Graph OneNote.

Мой класс ApiBaseResponse и класс GenericEntityResponse являются стандартными из документов MS без изменений.

Ниже мой код:

 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 ответ

Свойство называется "displayName", а не "name".

Другие вопросы по тегам