Sandeep Kumar

Sandeep Kumar

  • 1.1k
  • 683
  • 60.1k

how to assign below json to model class,

Jun 23 2023 6:01 AM

specially  my problem is to assign array uploadedfiles

how to receive this json data

{ "ID": 0, "StationId": 1, "UnitId": 1, "OutageTypeId": 1, "ZoneId": 2, "FinYear": "2018-2019", "PhotoTag": "azxxxcssac", "UploadedFiles": [{
"UploadedFiles": "data:image/jpeg;base64,/9j/4AA/QSkZ***Jggg==",
"UploadedFiles": "data:image/jpeg;base64,/9j/4AA/QSkZ***Jggg==",
"UploadedFiles": "data:image/jpeg;base64,/9j/4AA/QSkZ***Jggg==",
}] }

this is my model class

public class ImageUploadModel
{
    public int ID { get; set; }
    public int StationId { get; set; }
    public int UnitId { get; set; }
    public int OutageTypeId { get; set; }
    public int ZoneId { get; set; }
    public string FinYear { get; set; }
    public string PhotoTag { get; set; }
    public List<string> Image { get; set; }
}

this is my code to assign all value to model class

public List<object> Pms_INSERT_UPDATE_DATA_Using_Base(JObject jsonParam, int UserId)
{
    DataTable DtPhoto = new DataTable();
    List<object> returnVal = new List<object>();
    DtPhoto.Columns.Add("PhotoTag", typeof(System.String));
    ImageUploadModel IM = new ImageUploadModel();
    //List<int> returnVal = new List<int>();
    IM.ID = (int)jsonParam["ID"];
    IM.StationId = (int)jsonParam["StationId"];
    IM.UnitId = (int)jsonParam["UnitId"];
    IM.OutageTypeId = (int)jsonParam["OutageTypeId"];
    IM.ZoneId = (int)jsonParam["ZoneId"];
    IM.FinYear = (string)jsonParam["FinYear"];
    IM.PhotoTag = (string)jsonParam["PhotoTag"];
    IM.Image = (string)jsonParam["UploadedFiles"];
    other job-------------
}

Answers (6)