I have 2 json files and i am deserializing them separately in blazor c#, how can i make a join. so i can show country name also in page. eg AN = Netherlands .
json file 1 is below
{"CountryIso2":"AF","CountryName":"Afghanistan"},{"CountryIso2":"AN","CountryName":"Netherlands"}
json file 2 is below
{"Name":"something","Start":"2021-11-10T09:00:00","End":"2021-11-14T09:00:00","AdditionalInformation":"Volufda.</br>","Address":{"Information":"fasdfas","City":"Pelhu0159imov, Vysou010dina","CountryIso2":"AN"}}
my C# code is
public class Event
{
public string Name { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
public string AdditionalInformation { get; set; }
public Addressar Address { get; set; }
}
public class Addressar
{
public string Information { get; set; }
public string City { get; set; }
public string CountryIso2 { get; set; }
}
public class Country
{
public string CountryIso2 { get; set; }
public string CountryName { get; set; }
}
give solutions please.
3
Answers
You can use the Newtonsoft.Json.JsonConvert.DeserializeObject method. Start by parsing the json files into Event and Country objects. Then use the Select() method to combine them. For example, you can do something like this:
This will produce a file with json text that contains the events with country names information.
your first json file is invalid , you have to fix it
you can add CountryName property to an Addressar class
code