Using the Visual Studio integrated development environment and the C# programming language, we will develop a cross-platform mobile application for downloading Chuck Norris jokes in JSON format.
Information
JSON (JavaScript Object Notation) is a text-based open standard designed for human-readable data interchange. It originates from the JavaScript scripting language to represent simple data structures and associative arrays called objects.
Launch the Visual Studio integrated development environment.
Create a new project: Visual C# > Cross-Platform > Mobile App (Xamarin.Forms).
Name the project: JSON Reader 2.0.
Add additional packages to the project by installing Newtonsoft.Json from: Tools > NuGet Package Manager > Package Manager Console, by running the following command in the console:
Load and copy an example JSON from: https://api.chucknorris.io/jokes/random
Generate the C# class for the selected JSON from: http://json2csharp.com/
MainPage.xaml
The MainPage.xaml file contains the source code for the application's user interface design and is written in XAML. Copy (Ctrl+C) and paste (Ctrl+V) the fragment below into your application.
MainPage.xaml.cs
The MainPage.xaml.cs file contains the source code for the application's business logic and is written in C#. Copy (Ctrl+C) and paste (Ctrl+V) the fragment below into your application.
Demo
Run the application from the menu: Debug > Start Debugging or by pressing the F5 key.
Fig. 2.63. Demonstration of the cross-platform mobile application for downloading Chuck Norris jokes