return data from a Azure API json

141 views Asked by At

I have the following call to API. I need to write the return data in string format to a label instead of Console.WriteLine:

Using client = New HttpClient() Dim endpointUri As String, resourceId As String Dim str1 As String endpointUri = "https://outlook.office365.com/api/v1.0/me/events"

        Using request = New HttpRequestMessage(HttpMethod.[Get], endpointUri)
            request.Headers.Add("Authorization", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik1uQ19WWmNBVGZNNXBPWWlKSE1iYTlnb0VLWSIsImtpZCI6Ik1uQ19WWmNBVGZNNXBPWWlKSE1iYTlnb0VLWSJ9.eyJhdWQiOiJodHRwczovL291dGxvb2sub2ZmaWNlMzY1LmNvbS8iLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC9kYjNmMmI3ZS1hNzZmLTQwYjMtYmJiZC04NGMzMDhiODg2ZTcvIiwiaWF0IjoxNDMzODY3Mzg2")

            Using response = Await client.SendAsync(request)
                Dim content = Await response.Content.ReadAsStringAsync()
                Label1.Text = content.ToString
                For Each item In JObject.Parse(content)("value")
**Console.WriteLine**=("Message ""{0}"" received at ""{1}""", item("Subject"), item("DateTimeReceived"))
                Next
            End Using
        End Using
    End Using

Any help?

Thanks in advance

1

There are 1 answers

0
Rami Sarieddine On

The below code should do it. just add the json values to the text of the label.

Using request = New HttpRequestMessage(HttpMethod.[Get], endpointUri)
    request.Headers.Add("Authorization", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik1uQ19WWmNBVGZNNXBPWWlKSE1iYTlnb0VLWSIsImtpZCI6Ik1uQ19WWmNBVGZNNXBPWWlKSE1iYTlnb0VLWSJ9.eyJhdWQiOiJodHRwczovL291dGxvb2sub2ZmaWNlMzY1LmNvbS8iLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC9kYjNmMmI3ZS1hNzZmLTQwYjMtYmJiZC04NGMzMDhiODg2ZTcvIiwiaWF0IjoxNDMzODY3Mzg2")

    Using response = Await client.SendAsync(request)
        Dim content = Await response.Content.ReadAsStringAsync()
        Label1.Text = "" //clean the label from existing content

        For Each item In JObject.Parse(content)("value")
            Label1.Text += ("Message ""{0}"" received at ""{1}""", item("Subject"), item("DateTimeReceived"))
        Next
    End Using
End Using