My Json is fixed no change in json format
{ "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=="
}]
}
what should be my class to receive the json value
like
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
}
public class UploadedFile
{
public string UploadedFiles { get; set; }
}
i want to assign json data to my above class but how can i assign UploadedFiles array data to my my class variable
this way i m assigning the json value
public List
IM.UploadedFiles = ???------------Here is Issue
Mayooran NavamanyPosted Jun 24, 2023, 9:36 AM
Hi Sandeep Kumar
Your JSON is invalid; you've got an array that contains a single object with multiple properties that have the same name.
Can you try like this
cjardPosted Jun 25, 2023, 6:18 AM
Like this: https://dotnetfiddle.net/3SRMD4
Sandeep KumarPosted Jun 24, 2023, 12:33 PM
Sorry My json Is like
{ "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==", } ] }
cjardPosted Jun 24, 2023, 5:33 AM
Your JSON is invalid; you've got an array that contains a single object with multiple properties that have the same name.
Are you sure your "JSON" looks like that? It should look like:
not like
To parse this JSON you'll have to fix it so it is valid first. If you can't do that at source (fix the bug in the program generating the JSON) you'll have to do it with string manipulation to take out the { } and repeated "UploadedFiles" (to make it an array of strings)
When your json is fixed, visit https://app.QuickType.io to generate classes for it. Read the comments in the generated classes for advice on how to parse (it's really easy)
Note; the routines at QuickType will generate something that can parse the json as is, but you'll only get one of the files. See https://dotnetfiddle.net/6R5BF0 to see what I mean