The GetFromJsonAsync
method can be used to read data from a JSON file into a variable in a Blazor web application. The method works well for simple JSON files.
Example for GetFromJsonAsync
method:
@code {
private Students[]? students;
protected override async Task OnInitializedAsync()
{
students = await Http.GetFromJsonAsync<Students[]>("school.json");
}
public class Students
{
public int id { get; set; }
public string? name { get; set; }
public string? lastname { get; set; }
}
}
My question is, how can I read only the data in a given JSON header?
Example:
{
"book":[
{
"id":"444",
"language":"C",
"edition":"First",
"author":"Dennis Ritchie "
},
{
"id":"555",
"language":"C++",
"edition":"second",
"author":" Bjarne Stroustrup "
}
],
"student": [
{
"id":"01",
"name": "Tom",
"lastname": "Price"
},
{
"id":"02",
"name": "Nick",
"lastname": "Thameson"
}
]
}
I only would like to read the data under the "student" JSON header into a students
variable.