Hello: I had some C# code from former colleague using Newtonsoft.Json, I want to replace Newtonsoft.Json with built-in System.Text.Json, but I can’t reach my former colleague. I need some advice on how to re-write the statement with System.Text.Json. return JsonConvert.DeserializeObject<Icollection<SessionInfo>>(remoteSessions); The following is the code snippet: By the way, I am using Visual Studio 2019 (Version 16.8.6) on Windows 10 (Version 20H2) Thanks,
public class SessionInfo
{
[JsonProperty("description")]
public string Description
{
get;
set;
}
[JsonProperty("FrontendUrl")]
public string FrontendUrl
{
get;
set;
}
[JsonProperty("id")]
public string Id
{
get;
set;
}
[JsonProperty("title")]
public string Title
{
get;
set;
}
[JsonProperty("type")]
public string Type
{
get;
set;
}
[JsonProperty("DebuggerUrl")]
public string DebuggerUrl
{
get;
set;
}
}
public static async Task<ICollection<SessionInfo>> GetSessions(string Url)
{
using (var webClient = new HttpClient())
{
webClient.BaseAddress = new Uri(Url);
var remoteSessions = await webClient.GetStringAsync("/json");
return JsonConvert.DeserializeObject<ICollection<SessionInfo>>(remoteSessions);
}
}