MonoTouch.Dialog.JsonElement.FromJson C# (CSharp) Method

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
		public static JsonElement FromJson (JsonElement parent, JsonObject json, object data)
		{
			if (json == null)
				return null;

			var title = GetString (json, "title") ?? "";

			var group = GetString (json, "group");
			var url = GetString (json, "url");
			var radioSelected = GetString (json, "radioselected");
			JsonElement root;
			if (group == null){
				if (radioSelected == null)
					root = new JsonElement (title, url);
				else
					root = new JsonElement (title, new RadioGroup (int.Parse (radioSelected)), url);
			} else {
				if (radioSelected == null)
					root = new JsonElement (title, new Group (group), url);
				else {
					// It does not seem that we group elements together, notice when I add
					// the return, and then change my mind, I have to undo *twice* instead of once.

					root = new JsonElement (title, new RadioGroup (group, int.Parse (radioSelected)), url);
				}
			}
			root.jsonParent = parent;
			root.LoadSections (GetArray (json, "sections"), data);
			return root;
		}

Same methods

JsonElement::FromJson ( System.Json.JsonObject json ) : JsonElement
JsonElement::FromJson ( System.Json.JsonObject json, object data ) : JsonElement

Usage Example

コード例 #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));
        }
All Usage Examples Of MonoTouch.Dialog.JsonElement::FromJson