none
serialize the list into json string RRS feed

  • Question

  • how do I - Read json string from file (C:\Asp\Movie.json) and then -DEserialize the json string into a generic list? is that correct? any advice other than that?

    JsonConvert.DeserializeObject<List<Movie>>(File.ReadAllText(@"C:\\aspnet\\Movie.json"));


    • Edited by apilam Saturday, October 27, 2018 2:11 PM
    Friday, October 26, 2018 10:21 PM

All replies

  • hello,

    what you need, is to wrap the list of movies in an object that represents the root of your JsonPayload, consider the following class: 

    public class JsonPayload {
       public List<Movie> Movies { get; set; }
    }

    the Json should be:

    { "movies": [ { .... },

    { .... } ] }

    Best Regards,

    Mouad.

    Good Coding;


    Saturday, October 27, 2018 4:19 PM
  • Hi apilam,

    I would suggest that you could convert your Json text to c# class object, then deserialize JSON string the class object. 

    #convert your Json text to c# class object

    http://json2csharp.com/

    #Deserialize

    https://www.newtonsoft.com/json/help/html/deserializeobject.htm

    Best regards,

    Zhanglong 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 29, 2018 6:56 AM
    Moderator