unity3d json 转为 dictionary

来源:互联网 发布:深入浅出python中文版 编辑:程序博客网 时间:2024/05/18 05:41
private static Dictionary<string, object> deserializeToDictionary(string jo)
{
        Dictionary<string, object> values = JsonConvert.DeserializeObject<Dictionary<string, object>>(jo);
        Dictionary<string, object> values2 = new Dictionary<string, object>();
        foreach (KeyValuePair<string, object> d in values)
        {
            if (d.Value.GetType().FullName.Contains("Newtonsoft.Json.Linq.JObject"))
            {
                values2.Add(d.Key, deserializeToDictionary(d.Value.ToString()));
            }
            else
            {
                values2.Add(d.Key, d.Value);
            }


        }
        return values2;

}


dictionary = deserializeToDictionary(jsonText);