I have a XML like this:
<?xml version="1.0" encoding="UTF-8" ?>
<RESPONSE>
<SINGLE>
<KEY name="grades">
<MULTIPLE>
<SINGLE>
<KEY name="courseid">
<VALUE>3</VALUE>
</KEY>
<KEY name="grade">
<VALUE>40.00</VALUE>
</KEY>
<KEY name="rawgrade">
<VALUE>40.00000</VALUE>
</KEY>
<KEY name="rank">
<VALUE null="null"/>
</KEY>
</SINGLE>
</MULTIPLE>
</KEY>
<KEY name="warnings">
<MULTIPLE></MULTIPLE>
</KEY>
</SINGLE>
</RESPONSE>
I have converted it to JSON string like with below
string json = JsonConvert.SerializeXmlNode(doc);
But I need to assign my JSON into object of the below class type
public class Grades
{
public string Courseid { get; set; }
public string Grade{ get; set; }
public string Rawgrade{ get; set; }
public string Rank{ get; set; }
}
So that, I can access or assign my values into
Grade mygrade;
or later mygrade.Courseid
and now it looks like this:
{
"?xml": {
"@version": "1.0",
"@encoding": "UTF-8"
},
"RESPONSE": {
"SINGLE": {
"KEY": [
{
"@name": "grades",
"MULTIPLE": {
"SINGLE": {
"KEY": [
{
"@name": "courseid",
"VALUE": "3"
},
{
"@name": "grade",
"VALUE": "40.00"
},
{
"@name": "rawgrade",
"VALUE": "40.00000"
},
{
"@name": "rank",
"VALUE": {
"@null": "null"
}
}
]
}
}
},
{
"@name": "warnings",
"MULTIPLE": ""
}
]
}
}
}
But I need the JSON like the following
{
"courseid" : "3",
"grade": "40.00",
"rawgrade": "40.00000",
"rank": "null"
}
How can I assign properly my json to the above class format Grades? Can anyone please help me? I am new to ASP.NET Core.
Repsonse-object be some anonymous class?