-2

I want to parse JSON data with C# using the Newtonsoft.JSON library. But, I couldn't parse the JSON data because some JSON properties contain special characters that conflict with C# naming rules. You can see an example of JSON data from the link below:

Example JSON data: http://api.ipsw.me/v2.1/firmwares.json

How can I parse that kind of JSON file using C# class as a model?

Firat Eski
  • 661
  • 2
  • 7
  • 16

1 Answers1

1

Yo can use the JsonConvert class to read your json:

var deviceData = JsonConvert.DeserializeObject<DeviceData>("...yourJson..");

Your classes should look like this:

public class DeviceData {
    public DeviceList Devices { get; set; }
}

public class DeviceList {
    [JsonProperty(PropertyName = "AppleTV2,1")]
    public Device AppleTV21 { get; set; }

    [JsonProperty(PropertyName = "AppleTV3,1")]
    public Device AppleTV31 { get; set; }

    // continue ...
}

public class Device {
    public string Name { get; set; }
    public string BoardConfig { get; set; }
    public string Platform { get; set; }
    public string Cpid { get; set; }
    public string Bdid { get; set; }
    public Firmware[] Firmwares { get; set; }
}

public class Firmware {
    public string Version { get; set; }
    public string BuildId { get; set; }
    public string Sha1Sum { get; set; }
    public string Md5Sum { get; set; }
    public int Size { get; set; }
    public DateTime ReleaseDate { get; set; }
    public DateTime UploadDate { get; set; }
    public string Url { get; set; }
    public bool Signed { get; set; }
    public string Filename { get; set; }
}
makzr
  • 355
  • 2
  • 7