JSON:
[
{
"ProspectNo": "1000000073",
"MakerId": "C136771",
"MkrDate": "2015/11/26",
"TranID": null,
"ScoreData": {
"Client Experience": "1",
"Stability & Ownership": "7",
"Property ownership": "22",
"Co-app/Guarantor": "16",
"proposed cost": "1800000"
}
}
]
This is my attempted class:
[DataContract]
public class Score
{
[DataMember()]
public string ProspectNo;
[DataMember()]
public string MakerId;
[DataMember()]
public string MkrDate;
//[DataMember()]
//public string ScoreData;
[DataMember()]
//public Dictionary<string, string> ScoreData { get; set; }
public List<ScoreDataClass> ScoreData;
[DataMember()]
public string TranID;
}
[DataContract]
public class ScoreDataClass
{
[DataMember()]
public string key { get; set; }
[DataMember()]
public string value { get; set; }
}
The problem is that in my method :
public Main CalculateScore(Score scoreobj)
{
//ScoreData count is always 0.
}
Everything is fine except that I never get values in ScoreData.
I tried various Json to C# class generators available online such as http://jsonutils.com/ but it did not give desired results.
The JSON string will be sent from client as httppost. I can not change the way it is being sent.
NOTE:
I can not hard code it as (Name="Client Experience")
etc since I do not know how many or what its going be. It is not necessary that its always going to be Client Experience it could be anything.