I have the following json string:
{
"var1": "admin", // username
"var2":"2021-06-22T06:16:31.838Z", // timestamp
"var3": [
{
"name": "NAME_ARABIC",
"stringValue": "اسامہ محمد اسامہ عالم عالم"
},
{
"name": "NAME_ENGLISH",
"stringValue": "Alam Alam"
}
],
"var4": [
{
"code": "MOFA",
"fullName": "Ministry of Foreign Affairs",
"shortName": "MOFA",
"typeOrganization": "Firm",
"fullNameOrganization": "Ministry of Foreign Affairs",
"shortNameOrganization": "MOFA",
"codeOrganization": "MOFA"
}
]
}
I am using the following code to get the values from the json and I can get var1 and var2 but I am not sure how to get var3 and var4 that are arrays. Can you please help me with that?
[HttpPost]
[Route("addCardRequest")]
public ContentResult addCardRequest([FromBody] Object json)
{
string jsonInput = json.ToString();
Dictionary<string, string> jsonDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonInput);
hmacRequest hmacReq = new hmacRequest();
hmacReq.var1 = jsonDic["var1"];
hmacReq.var2 = jsonDic["var2"];
}
"..., name": { "ARABIC" : "...", "ENGLISH": "Alam Alam"}, ..."var1always astring? Isvar3always an array ofname/stringValuepairs? etc. If so, then use a proper class structure that matches that format.