[Solved] Read Json using C# [closed]


Your json is broken and many json parser would complain about it.

I’ll use Json.Net for parsing.

    string json = @"{data: { ""1000"": { ""country-id"": 1000, ""name1"": { ""name"": ""Afghanistan"", }, }, ""4000"": { ""country-id"": 4000, ""name1"": { ""name"": ""Albania"", } }";

    var countries = ((JObject)JsonConvert.DeserializeObject(json))["data"]
        .Children()
        .Select(x => new
        {
            Id = (int)x.First()["country-id"],
            Name = (string)x.First()["name1"]["name"],
        })
        .ToList();

6

solved Read Json using C# [closed]