I have a model that looks like:
public class SearchResult
{
public bool success { get; set; }
public SearchData data { get; set; }
}
public class SearchData
{
public string UploadDate { get; set; }
public List<UserImages> Images { get; set; }
}
public class UserImages
{
public string Filename { get; set; }
public string FileId { get; set; }
}
My collection is returning result in the following format
FileId FileName UploadDate
148847 IMG_1.JPG Mar-2012
135710 IMG_8.JPG Mar-2012
143817 IMG_6.JPG Jul-2013
143873 IMG_5.JPG Aug-2014
145766 IMG_4.JPG Aug-2015
145820 IMG_3.JPG Jan-2016
145952 IMG_2.JPG Jan-2016
I want to serialize the above collection so that I can generate the following JSON:
{
"success": true,
"SearchData": {
"UploadDate": "MAR-2012",
"UserImages": [{
"Filename": "IMG_1.JPG",
"FileId ": "148847"
}, {
"Filename": "IMG_8.JPG",
"FileId ": "135710"
}],
"UploadDate": "Jul-2013",
"UserImages": [{
"Filename": "IMG_6.JPG",
"FileId ": "143817"
}]
}
}
I just can't get the iteration working. How can I iterate the collection to create the object of my model class to serialize it later?