How to deserialize JSON to objects of the correct type, without having to define the type before hand?

前端 未结 2 1440
既然无缘
既然无缘 2020-12-04 01:36

I searched through similar questions and couldn\'t find anything that quite matched what i was looking for.

New to C# so bear with me please.

I have some jso

2条回答
  •  悲&欢浪女
    2020-12-04 01:57

    Deserialize your JSON into the most basic form:

    Dictionary theData= new JavaScriptSerializer().Deserialize>(jsonString);
    
    string baseItemName = (string)theData["baseItem"];
    
    Dictionary someNode= (Dictionary)theData["something"];
    
    string anything = (string)someNode["anything"];
    string nothing = (string)someNode["nothing"];
    

    The call to Deserialize() creates a tree of Dictionary that you can traverse at will.

提交回复
热议问题