forked from alenthomas/json-parsing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsharp.cs
32 lines (28 loc) · 871 Bytes
/
csharp.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Net;
using Newtonsoft.Json;
namespace Parsing
{
class Program
{
// Get the content from the given URL as a string.
static string FetchDataFromUrl(string url)
{
using (var client = new WebClient())
{
return client.DownloadString(url);
}
}
static void Main(string[] args)
{
// Get the JSON data from the Fixer API.
var json = FetchDataFromUrl("http://api.fixer.io/latest?symbols=MYR&base=SGD");
dynamic results = JsonConvert.DeserializeObject(json);
// Find the MYR conversion rate.
var rate = results.rates.MYR;
// Output the conversion rate from SGB to MYR.
Console.WriteLine($"SGD1 = MYR{rate}");
Console.ReadLine();
}
}
}