I have a Jtoken having structure as. The below structure have even more properties than below but I have to use only the below ones
{{ "PersonId": 1234, "State": "Florida", "Gender": "Male", "Married ": 1, "SalaryUnderHundredDollar ": 1, }}
I have created a class Person as
public class Person
{
public int PersonId {get;set;}
public string State {get;set;}
public string Gender {get;set;}
public bool Married {get; set}
public bool SalaryUnderHundredDollar {get;set}
}
I am converting the above Jtoken into dictionary as :
var dict = jtoken.First.ToObject<Dictionary<string, object>>().ToDictionary(x => x.Key, x => x.Value);
This will give all the properties of the Person but I want only the above ones.And now I have to convert
Dictionary<string,object> to Dictionary<string,class>
I am doing the following:
var dict2= dict.Where(x => fieldsRequired.Contains(x.Key)).ToDictionary(x => x.Key, x => (Person)x.Value);
fieldsRequired is a list of string fields which I need since in Jtoken there are number of fields.
But this conversion is not working.
Any help?