how to deserialize complex json to hashtable+array style

632 views c#
9

here is my code:

        string json = "{'047084de7e289476991970194dd14513':{'reload':[]}}";
        var r = JsonConvert.DeserializeObject(json);
        Console.WriteLine($"{r}");

in my json, hashtable include inner hashtable, the r["047084de7e289476991970194dd14513"] result is jobject, but I hope its a hashtable, how should I do?

I hope find a way like javascript JSON.parse to get a object that all inner key and value can accessable

I use mono in linux, so I cannot use JavaScriptSerializer

answered question

1 Answer

0

I find JsonConvert.DeserializeObject return JObject or JArray are like Hashtable and Array, so if parse result is jobject, I can cast result to JObject

        string json = "{'047084de7e289476991970194dd14513':{'reload':[]}}";
        var r = (JObject) JsonConvert.DeserializeObject(json);
        Console.WriteLine($"{r["047084de7e289476991970194dd14513"]}");

posted this

Have an answer?

JD

Please login first before posting an answer.