C
C#8mo ago
Livid

✅ HttpClient to Json

hey i tried a number of ways to get json from response.Content.ReadAsStringAsync()
6 Replies
Livid
Livid8mo ago
but i don't want to create the class to use by myself and no newtonsoft :(
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
SG97
SG978mo ago
no System.Text.Json either? agree with Tebe, that's the only proper way
nkowalec
nkowalec8mo ago
You can use System.Text.Json to deserialization, or if you don't want DTO you can parse JsonDocument
string text = "{ \"prop1\": \"value1\" }";
var doc = JsonDocument.Parse(text);
var val = doc.RootElement.GetProperty("prop1").GetString();
string text = "{ \"prop1\": \"value1\" }";
var doc = JsonDocument.Parse(text);
var val = doc.RootElement.GetProperty("prop1").GetString();
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Livid
Livid8mo ago
finally i did
var result = await response.Content.ReadAsStringAsync();
JsonNode node = JsonNode.Parse(result);
... = node[0]["name"].ToString();
var result = await response.Content.ReadAsStringAsync();
JsonNode node = JsonNode.Parse(result);
... = node[0]["name"].ToString();