I want to deserialize this json file into a native list or array so can I use it in my code. I tried many ways but every time I get different errors, I included the latest one here, please provide my the right way to deserialize the json in the mentioned url.
Message=Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[WebRequest.myRequest4+TseReport]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. 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) 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."
class Program
{
args = myRequest4.TseGet().Result;
}
public class TseReport
{
public string t { get; set; }
public string title { get; set; }
public string des { get; set; }
public string l { get; set; }
public string w { get; set; }
public string img { get; set; }
}
public async static Task<string[]> TseGet()
{
string[] str = new string[2];
Uri uri = new Uri("https://tse.ir/news/newsTag/tag_a1.json?_=1604038960668");
HttpClientHandler handler = new HttpClientHandler();
List<TseReport> model = null;
HttpClient client = new HttpClient();
try
{
var task = client.GetAsync(uri)
.ContinueWith((taskwithresponse) =>
{
var response = taskwithresponse.Result;
var jsonString = response.Content.ReadAsStringAsync();
jsonString.Wait();
model = JsonConvert.DeserializeObject<List<TseReport>>(jsonString.Result);
});
task.Wait();
Thread.Sleep(50);
}
catch (Exception ex)
{
string err = ex.GetBaseException().Message;
str[1] = err;
}
Console.Write(model);
Console.WriteLine("finished");
return str;
}