using Newtonsoft.Json.Linq;
using System.Collections.Generic;
public static void Main()
var obj = JsonConvert.DeserializeObject<dynamic>("{\"Gender\": \"M\", \"Specialty\": \"Medicina general\"}");
UserProfile up = new UserProfile
CustomData = new { Gender = "F", Specialty = "Medicina general" }
TestData data = new TestData
CustomData = JsonConvert.DeserializeObject<Dictionary<string,string>>("{\"Gender\": \"M\", \"Specialty\": \"Medicina general\"}")
Dictionary<string, string> customData = JsonConvert.DeserializeObject<Dictionary<string,string>>("{\"Gender\": \"M\", \"Specialty\": \"Medicina general\"}");
customData.TryGetValue("Gender", out gender);
Console.WriteLine(gender);
var di = GetKeyValue(data, "CustomData.Gender");
object dn = (object)JsonConvert.DeserializeObject<dynamic>("{\"Gender\": \"M\", \"Specialty\": \"Medicina general\"}");
Console.WriteLine(dn.GetType());
object cd = JObject.Parse("{\"Gender\": \"M\", \"Specialty\": \"Medicina general\"}");
Console.WriteLine(cd.GetType());
Console.WriteLine(JsonConvert.SerializeObject(up));
Console.WriteLine(up.CustomData);
Console.WriteLine(up.CustomData.GetType());
Console.WriteLine("--------");
Console.WriteLine(JsonConvert.SerializeObject(data));
Console.WriteLine(data.CustomData);
Console.WriteLine(data.CustomData.GetType());
var rr = GetPropertyValue(up, "CustomData.Gender");
public static object GetKeyValue(object src, string propName)
if (src == null) throw new ArgumentException("Value cannot be null.", "src");
if (propName == null) throw new ArgumentException("Value cannot be null.", "propName");
if(propName.Contains("."))
var temp = propName.Split(new char[] { '.' }, 2);
return GetKeyValue(GetKeyValue(src, temp[0]), temp[1]);
var prop = src.GetType().GetProperty(propName);
return prop != null ? prop.GetValue(src, null) : null;
public static object GetPropertyValue(object src, string propName)
if (src == null) throw new ArgumentException("Value cannot be null.", "src");
if (propName == null) throw new ArgumentException("Value cannot be null.", "propName");
if(propName.Contains("."))
var temp = propName.Split(new char[] { '.' }, 2);
return GetPropertyValue(GetPropertyValue(src, temp[0]), temp[1]);
var prop = src.GetType().GetProperty(propName);
return prop != null ? prop.GetValue(src, null) : null;
public string Name { get; set; }
public object CustomData { get; set; }
public object CustomData { get; set; }