Consuming REST services with HttpClient
If we have an app that displays data, the chances are that it comes from somewhere outside the device, say somewhere like the Internet.
Getting ready
To work with JSON responses, we need to install the Newtonsoft.Json
NuGet package or the Json.NET
component. This is an advanced JSON parser; however, we can make use of the DataContractJsonSerializer
type or any other serializer for JSON.
How to do it...
In order to obtain data from the Internet or a local network, we use HTTP requests. In this recipe, we access data from http://jsonplaceholder.typicode.com/posts/1:
- Access JSON data from the HTTP location in the form:
{ "userId": 1, "id": 1, "title": "sunt aut facere repellat provident occaecati", "body": "quia ...
Get Xamarin Mobile Development for Android Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.