how can i get the "Points" value using JsonConvert.DeserializeObject can anyone help me
{ "data": { "Gamers": [ { "id": "5397742571", "startTime": "Thu, 28 Jun 2022 00:04:13 GMT", "points": 11.647601, "hash": { "id": "xxxxxxxxxxxx", "hash": "xxxxxxxxxx", "__typename": "GamerRace" }, } ] }
-
Welcome to StackOverflow. Well, would recommend using tools such as json2csharp to convert the JSON to C# classes.Yong Shun– Yong Shun2022-06-30 02:15:29 +00:00Commented Jun 30, 2022 at 2:15
-
Why did you tag this question with [api] when the API tag description states: "DO NOT USE. Use specific tags like [google-cloud-platform], [facebook], [amazon-web-services] instead or [api-design] where applicable. Questions asking to recommend or find an API are off-topic." ? Also, none of those seem like they would be relevant to your question.ProgrammingLlama– ProgrammingLlama2022-06-30 02:22:14 +00:00Commented Jun 30, 2022 at 2:22
Add a comment
|
1 Answer
First of all. Your json have some issue. I fix it and here is it.
{
"data": {
"Gamers": [
{
"id": "5397742571",
"startTime": "Thu, 28 Jun 2022 00:04:13 GMT",
"points": 11.647601,
"hash": {
"id": "xxxxxxxxxxxx",
"hash": "xxxxxxxxxx",
"__typename": "GamerRace"
}
}
]
}
}
Now Create Model for this json like below.
public class Data
{
public List<Gamer> Gamers { get; set; }
}
public class Gamer
{
public string id { get; set; }
public string startTime { get; set; }
public double points { get; set; }
public Hash hash { get; set; }
}
public class Hash
{
public string id { get; set; }
public string hash { get; set; }
public string __typename { get; set; }
}
Now its time to convert your json into c# object.
Data people = JsonConvert.DeserializeObject<Data>(yourJson);
Hope it helps you buddy.