I have a minimal API in .NET 6. In this API, I call a 3rd party API which returns normal json formatted data by using this code:
HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
jsonResponse = await response.Contet.ReadAsStringAsync
}
jsonResponse
looks like this for example:
{
"response":
{
"AnArray": [
"Id": 11,
"AnotherId":22
],
"AndACityArray": [
"New York",
"London",
"Berlin"
],
"ADirectionArray": [
"North",
"East",
"South",
"West"
]
}
}
If I return this as it is, in postman it is escaped like
{\"response\": and so on}
If I replace the escape chars it looks good, but its still plain text.
I tried to return it as it is. I tried JsonConvert.DeserializeObject
to dynamic or to object. In this case, it is returned as JSON, but there are just empty arrays.
{response:[
[
[]
],
[
[]
],
[
[]
],
}
The structure of that JSON can change, so I can't just define a class to deserialize it.
I tried different results. Results.Text
, Results.JSON
, converted it back and forwards.
I just want to pass the json data I get from the 3rd party API, straight through my minimal API and return it.