private Dictionary<String, Object> JsonToDictionary(dynamic json) {
if (json == null) return null;
var jprops = ((System.Collections.IEnumerable)json).Cast<JProperty>();
var dict = jprops.ToDictionary(jprop => jprop.Name, jprop => {
var val = jprop.Value as JValue;
if (val != null) {
return val.Value;
} else if (jprop.Value as JArray != null){
return jprop.Value as JArray;
} else {
return jprop.Value as JObject;
}
});
return dict;
}