Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

JObject response = JsonConvert.DeserializeObject(json); not working properly.

$
0
0

var json = await httpClient.GetStringAsync(
"https://www.instagram.com/"
//https://www.instagram.com/tmteice/#access_token=7376071860.4a7135d.99d3c8a954d64424889fe17e16b96ee0
);

        JObject response = JsonConvert.DeserializeObject<dynamic>(json);


        var items = response.Value<JArray>("items");

        try
        {

            var instagramItems = new List<InstagramItem>();

            foreach (var item in items)
            {
                var instagramItem = new InstagramItem
                {
                    UserName = item.Value<JObject>("user").Value<string>("username"),
                    FullName = item.Value<JObject>("user").Value<string>("full_name"),
                    ProfilePicture = item.Value<JObject>("user").Value<string>("profile_picture"),
                    LowResolutionUrl = item.Value<JObject>("images").Value<JObject>("low_resolution").Value<string>("url"),
                    StandardResolutionUrl = item.Value<JObject>("images").Value<JObject>("standard_resolution").Value<string>("url"),
                    ThumbnailUrl = item.Value<JObject>("images").Value<JObject>("thumbnail").Value<string>("url"),
                    Text = item.Value<JObject>("caption").Value<string>("text"),
                    CreatedTime = item.Value<JObject>("caption").Value<string>("created_time"),
                    LikesCount = item.Value<JObject>("likes").Value<int>("count"),
                    CommentsCount = item.Value<JObject>("comments").Value<int>("count"),
                };

                instagramItems.Add(instagramItem);
            }

            InstagramItems = instagramItems;
        }
        catch (Exception ex)
        {

        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

}


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>