using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MercatorApi;
using MercatorExtensions;
using MercatorUi;

namespace MyNameSpace
{
    public class Class1 : MercatorUi.Interfaces.IExec
    {

        public void Main()
        {
            string jsonString = Api.XgetUrl("http://api.icndb.com/jokes/random");
            if (!string.IsNullOrEmpty(jsonString))
            {
                RootObject jsonObject = Api.JsonConvertDeserializeObject<RootObject>(jsonString);
                if (jsonObject.type == "success")
                    Dialogs.Stop(jsonObject.value.joke);
            }
        }
    }

    // Klassen verkregen via http://json2csharp.com/

    public class Value
    {
        public int id { get; set; }
        public string joke { get; set; }
        public List<string> categories { get; set; }
    }

    public class RootObject
    {
        public string type { get; set; }
        public Value value { get; set; }
    }
}