反序列化JSON字符串字典<字符串,对象>

问题描述:

我有这样的字符串:

[{ "processLevel" : "1" , "segments" : [{ "min" : "0", "max" : "600" }] }]

我反序列化对象:

I'm deserializing the object:

object json = jsonSerializer.DeserializeObject(jsonString);

对象是这样的:

The object looks like:

object[0] = Key: "processLevel", Value: "1"
object[1] = Key: "segments", Value: ...

和试图建立一个词典:

Dictionary<string, object> dic = json as Dictionary<string, object>;

DIC 获得

什么是问题?

由于mridula答案,为什么你越来越null.But如果你想直接转换成JSON字符串百科,你可以试试下面的code段。

As mridula answer why your are getting null.But if you want to directly convert the json string to dictionay you can try following code snippet.

    Dictionary<string, object> values = 
JsonConvert.DeserializeObject<Dictionary<string, object>>(json);