Deserialize JSON with C#

前端 未结 10 1461
一生所求
一生所求 2020-11-21 05:57

I\'m trying to deserialize a Facebook friend\'s Graph API call into a list of objects. The JSON object looks like:

{\"data\":[{\"id\":\"518523721\",\"name\"         


        
10条回答
  •  难免孤独
    2020-11-21 06:13

    You can use this extensions

    public static class JsonExtensions
    {
       public static T ToObject(this string jsonText)
       {
           return JsonConvert.DeserializeObject(jsonText);
       }
    
       public static string ToJson(this T obj)
       {
           return JsonConvert.SerializeObject(obj);
       }
    }
    

提交回复
热议问题