O'Reilly logo

Xamarin Mobile Development for Android Cookbook by Matthew Leibowitz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

  1. Access JSON data from the HTTP location in the form:
    { "userId": 1, "id": 1, "title": "sunt aut facere repellat provident occaecati", "body": "quia ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required