FromJson() public static method

public static FromJson ( JsonElement parent, System.Json.JsonObject json, object data ) : JsonElement
parent JsonElement
json System.Json.JsonObject
data object
return JsonElement
Beispiel #1
0
        public override void Selected(DialogViewController dvc, UITableView tableView, NSIndexPath path)
        {
            if (Url == null)
            {
                base.Selected(dvc, tableView, path);
                return;
            }

            tableView.DeselectRow(path, false);
            if (loading)
            {
                return;
            }
            var cell    = GetActiveCell();
            var spinner = StartSpinner(cell);

            loading = true;

            var wc = new WebClient();

            wc.DownloadStringCompleted += delegate(object sender, DownloadStringCompletedEventArgs e){
                dvc.BeginInvokeOnMainThread(delegate {
                    loading = false;
                    spinner.StopAnimating();
                    spinner.RemoveFromSuperview();
                    if (e.Result != null)
                    {
                        try {
                            var obj = JsonValue.Load(new StringReader(e.Result)) as JsonObject;
                            if (obj != null)
                            {
                                var root   = JsonElement.FromJson(obj);
                                var newDvc = new DialogViewController(root, true)
                                {
                                    Autorotate = true
                                };
                                PrepareDialogViewController(newDvc);
                                dvc.ActivateController(newDvc);
                                return;
                            }
                        } catch (Exception ee) {
                            Console.WriteLine(ee);
                        }
                    }
                    IUIAlertViewDelegate avd = null;
                    var alert = new UIAlertView("Error", "Unable to download data", avd, "OK", null);
                    alert.Show();
                });
            };
            wc.DownloadStringAsync(new Uri(Url));
        }
Beispiel #2
0
        public override void Selected(DialogViewController dvc, UITableView tableView, NSIndexPath path)
        {
            if (Url == null)
            {
                base.Selected(dvc, tableView, path);
                return;
            }

            tableView.DeselectRow(path, false);
            if (loading)
            {
                return;
            }
            var cell    = GetActiveCell();
            var spinner = StartSpinner(cell);

            loading = true;

            var request = new NSUrlRequest(new NSUrl(Url), NSUrlRequestCachePolicy.UseProtocolCachePolicy, 60);

            /*var connection = */ new NSUrlConnection(request, new ConnectionDelegate((data, error) => {
                loading = false;
                spinner.StopAnimating();
                spinner.RemoveFromSuperview();
                if (error == null)
                {
                    try {
                        var obj = JsonValue.Load(new StreamReader(data)) as JsonObject;
                        if (obj != null)
                        {
                            var root   = JsonElement.FromJson(obj);
                            var newDvc = new DialogViewController(root, true)
                            {
                                Autorotate = true
                            };
                            PrepareDialogViewController(newDvc);
                            dvc.ActivateController(newDvc);
                            return;
                        }
                    } catch (Exception ee) {
                        Console.WriteLine(ee);
                    }
                }
                var alertController = UIAlertController.Create("Error", "Unable to download data", UIAlertControllerStyle.Alert);
                alertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (obj) => { }));
                UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alertController, true, () => { });
            }));
        }