these classes were generated by visual studio
{
public class Rootobject
{
public Bird[]? Albatros { get; set; }
public Bird[]? Avocet { get; set; }
public Bird[]? Bustard { get; set; }
public Bird[]? Cassowary { get; set; }
public Bird[]? Coot { get; set; }
public Bird[]? Crake { get; set; }
public Bird[]? Crane { get; set; }
public Bird[]? Dotterel { get; set; }
public Bird[]? Emoes { get; set; }
public Bird[]? Fowl { get; set; }
public Bird[]? Grebe { get; set; }
public Bird[]? Gull { get; set; }
public Bird[]? Hen { get; set; }
public Bird[]? Heron { get; set; }
public Bird[]? Ibis { get; set; }
public Bird[]? Jacana { get; set; }
public Bird[]? Mollymawk { get; set; }
public Bird[]? Noddy { get; set; }
public Bird[]? Oystercatcher { get; set; }
public Bird[]? Penguin { get; set; }
public Bird[]? Petrel { get; set; }
public Bird[]? Pigeons { get; set; }
public Bird[]? Plover { get; set; }
public Bird[]? Prion { get; set; }
public Bird[]? Quail { get; set; }
public Bird[]? Rail { get; set; }
public Bird[]? Sandpiper { get; set; }
public Bird[]? Skua { get; set; }
public Bird[]? Spoonbill { get; set; }
public Bird[]? Stilt { get; set; }
public Bird[]? Stork { get; set; }
public Bird[]? StormPetrel { get; set; }
public Bird[]? Tern { get; set; }
public Bird[]? Ternlet { get; set; }
public Bird[]? Turkey { get; set; }
public Bird[]? Turnstone { get; set; }
public Bird[]? Wanderer { get; set; }
public Bird[]? Wonga { get; set; }
}
public class Bird
{
[JsonPropertyName("Ned")]
public string? ned { get; set; }
[JsonPropertyName("En")]
public string? eng { get; set; }
[JsonPropertyName("Fr")]
public string? fra { get; set; }
[JsonPropertyName("Lat")]
public string? lat { get; set; }
[JsonPropertyName("Bestand")]
public string? imgfile { get; set; }
[JsonPropertyName("Komt_voor_in")]
public string? distribution { get; set; }
[JsonPropertyName("zeldzaam")]
public string? rarity { get; set; }
}
public enum Species
{
Albatros,
Avocet,
Bustard,
Cassowary,
Coot,
Crake,
Crane,
Dotterel,
Emoes,
Fowl,
Grebe,
Gull,
Hen,
Heron,
Ibis,
Jacana,
Mollymawk,
Noddy,
Oystercatcher,
Penguin,
Petrel,
Pigeons,
Plover,
Prion,
Quail,
Rail,
Sandpiper,
Skua,
Spoonbill,
Stilt,
Stork,
StormPetrel,
Tern,
Ternlet,
Turkey,
Turnstone,
Wanderer,
Wonga
}
}
I want to input a specie as a Species and then select the birds belonging to the specie.
Also when I input the name or part of the name of a bird I want to indicate with a second input field whether the name is in eng, ned or lat or fr
The problem with the specie is that the RootObject is not enumerable, so I had to make a switch with all the species to get to the birds.
Same for the birds. I wonder it is possible to do something like this:
searchspecie = "Albatros"
Bird[] birds= birdsofaussie.searchspecie where birdsofaussie is the deserialized json file which was used to create the classes.
Thank you in advance for any suggestions
What I have tried:
This works
string fileContents = LeesJson();
Rootobject? birdsOfAustralia = JsonSerializer.Deserialize<Rootobject>(fileContents);
Bird[] birds = birdsOfAustralia.Albatros;
nofBirds = birds.Count();
for (int j = 0; j < nofBirds; j++)
{
if (birds[j].eng.IndexOf(SearchName, 0) >= 0)
{
gezochteVogels[gv] = birds[j];
gv++;
}
}
birds = birdsOfAustralia.Avocet;
nofBirds = birds.Count();
for (int j = 0; j < nofBirds; j++)
{
if (birds[j].eng.IndexOf(SearchName, 0) >= 0)
{
gezochteVogels[gv] = birds[j];
gv++;
}
}
...
Now I have to make exact the the same module but eng replaced by ned or fr or lat.
I want to avoid this and if possible use a foreach for the species