C
C#13mo ago
Livid

✅ HttpClient to Json

hey i tried a number of ways to get json from response.Content.ReadAsStringAsync()
6 Replies
Livid
LividOP13mo ago
but i don't want to create the class to use by myself and no newtonsoft :(
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SG97
SG9713mo ago
no System.Text.Json either? agree with Tebe, that's the only proper way
nkowalec
nkowalec13mo 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 User13mo ago
Message Not Public
Sign In & Join Server To View
Livid
LividOP13mo 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();
Want results from more Discord servers?
Add your server