Deserialize JSON into Object C#

前端 未结 5 1669
广开言路
广开言路 2020-11-28 14:06

Hello I am in desperate need of some help. I have a json file, with an array of json objects. I cannot figure out how to deserialize it into a list of this object.

5条回答
  •  孤街浪徒
    2020-11-28 14:18

    using(StreamReader reader = new StreamReader(@"path"))
    {
         string jsonString = reader.ReadToEnd();
         JArray myObj = (JArray)JsonConvert.DeserializeObject(jsonString);
    
         var player = new Player();
         player.statsBase = myObj.ToObject>();
    }
    

    This is how i finally accomplished it. I'm not sure if the above answers will work for multiple JSON objects in the same file.

提交回复
热议问题