コード例 #1
0
        public void UsersJson()
        {
            var           client   = new RestClient("https://jsonplaceholder.typicode.com");
            var           request  = new RestRequest("users");
            IRestResponse response = client.Execute(request);

            users = JsonConvert.DeserializeObject <List <User> >(response.Content);

            foreach (User user in users)
            {
                context.Users.Add(user);
                context.SaveChanges();
            }
        }
コード例 #2
0
        public void PostsJson()
        {
            var           client   = new RestClient("https://jsonplaceholder.typicode.com");
            var           request  = new RestRequest("posts");
            IRestResponse response = client.Execute(request);

            posts = JsonConvert.DeserializeObject <List <Post> >(response.Content);

            foreach (Post post in posts)
            {
                context.Posts.Add(post);
                context.SaveChanges();
            }
        }