i have a model class by which i bind my List<classname> and it look like this
public class Response
{
public vMetaData vData { get; set; }
public List<Data> data { get; set; }
}
public class vMetaData
{
public string version { get; set; }
}
public class Data
{
public string ID { get; set; }
public List<studentData> studentData { get; set; }
public Dictionary<string,dynamic> FeeData { get; set; }
}
public class studentData
{
public string StudentID { get; set; }
public string StudentName { get; set; }
}
public class FeeData
{
public string key { get; set; }
public object value { get; set; }
}
now i have one list for studentdata and one dictionary for feedata
i need below json as a final result:-
{
"Vdata": {
"version": "1.0",
},
"data": [
{
"ID": "0001",
"studentData": [
{
"StudentID": "0001",
"StudentName": "std1"
}
],
"FeeData ": [
{
"key": "feeStatus",
"value": "Submit"
},
{
"key": "StudentStatus",
"value": "Active"
},
]
},
{
"ID": "0002",
"studentData": [
{
"StudentID": "0002",
"StudentName": "std2"
}
],
"FeeData ": [
{
"key": "feeStatus",
"value": "Submit"
},
{
"key": "StudentStatus",
"value": "InActive"
},
]
}
]
}
how can i convert my data into this format, can any one suggest me
What I have tried:
i tried this but it create new object on every loop so only last value is bind.
for (int i = 0; i < studentdata.Count; i++)
{
var studentitem = "["+ JsonConvert.SerializeObject(studentdata[i])+ "]";
List<studentData> student_data = JsonConvert.DeserializeObject<List<studentData>>(studentitem);
var item = JsonConvert.SerializeObject(FeeData[i]);
Feeitem = item.Replace("[", "").Replace("]","");
var feedata = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(Feeitem);
Response = new Response
{
vData = new vMetaData
{
version = "1.0",
},
data = new List<data> {
new data { entRefIDs = EntitilementRefId, studentData = student_data,FeeData=feedata }
}
};
}
return Response;