Olá Pessoal Bom Dia estou tendo uma grande dificuldade em conseguir ler os dados deste WebService.
https://olinda.bcb.gov.br/olinda/servico/PTAX/versao/v1/odata/CotacaoDolarDia(dataCotacao=@dataCotacao)?@dataCotacao=%2705-05-2020%27&$format=json&$select=cotacaoVenda
Eu li algum material na internet mas não consegui solucionar o meu problema por falta de conhecimento de minha parte.
Tenho esta função que consegue conectar não consegue transformar os dados de uma forma que eu consiga usar.
Private Async Sub Teste()
Dim Uri As String
Uri = "https://olinda.bcb.gov.br/olinda/servico/PTAX/versao/v1/odata/CotacaoDolarDia(dataCotacao=@dataCotacao)?@dataCotacao=%2705-05-2020%27&$format=json&$select=cotacaoVenda"
Using client = New HttpClient()
Using response = Await client.GetAsync(Uri)
If response.IsSuccessStatusCode Then
Dim ProdutoJsonString = Await response.Content.ReadAsStringAsync()
Dim lista = JsonConvert.DeserializeObject(Of List(Of Ptax))(ProdutoJsonString).ToList()
Else
MessageBox.Show("Não foi possível obter o produto : " + response.StatusCode)
End If
End Using
End Using
End Sub
Public Class Ptax
Public Property cotacaoVenda As String
End Class
Este webService me retorna esse valor
{"@odata.context":"https://was-p.bcnet.bcb.gov.br/olinda/servico/PTAX/versao/v1/odata$metadata#_CotacaoDolarDia(cotacaoVenda)","value":[{"cotacaoVenda":5.53540}]}
e a informação que eu preciso de dentro dela é esta "5.53540"
E é nesta parte do código que da erro
Dim lista = JsonConvert.DeserializeObject(Of List(Of Ptax))(ProdutoJsonString).ToList()
E o erro é este
{"Cannot deserialize the current JSON object (e.g. {""name"":""value""}) into type 'System.Collections.Generic.List`1[MA_Historico_Trade.Ptax]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize
correctly." & vbCrLf & "To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array
or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object." & vbCrLf & "Path '['@odata.context']', line 1, position 18."}
Se alguém puder me dar uma luz de como fazer fico muito grato, estou perdido no escuro kkkk
Desde já Grato pela atenção de todos.
Att Jonatas Marques