Beispiel #1
0
        static void convertToJToken_recursive(JsonTreeViewItem tvi_cur, JObject jobj_cur)
        {
            if (tvi_cur == null || jobj_cur == null)
            {
                return;
            }

            JToken cur_jtok = jobj_cur;

            // 여기서부터는 property 로 시작
            foreach (var v in tvi_cur.Items)
            {
                JsonTreeViewItem tvi_child = v as JsonTreeViewItem;
                if (tvi_child == null)
                {
                    continue;
                }

                JsonTreeViewItemHeader pan = tvi_child.Header as JsonTreeViewItemHeader;
                if (pan == null)
                {
                    continue;
                }

                // pan(MyTreeViewItem.Header) = key, val or val.type, button
                JsonTextBox tb_key      = pan.Children[0] as JsonTextBox;
                ValuePanel  panel_value = pan.Children[1] as ValuePanel;

                switch (panel_value.type)
                {
                case JTokenType.Object:
                {
                    JObject   jobj  = new JObject();
                    JProperty jprop = new JProperty(tb_key.Text, jobj);
                    (cur_jtok as JObject).Add(jprop);
                    convertToJToken_recursive(tvi_child, jobj);
                }
                break;

                case JTokenType.Array:
                {
                    JArray    jarr  = new JArray();
                    JProperty jprop = new JProperty(tb_key.Text, jarr);
                    (cur_jtok as JObject).Add(jprop);
                    for (int i = 0; i < tvi_child.Items.Count; i++)
                    {
                        JObject jobj = new JObject();
                        jarr.Add(jobj);
                        convertToJToken_recursive(tvi_child.Items[i] as JsonTreeViewItem, jobj);
                    }
                }
                break;

                default:
                {
                    JProperty jprop = new JProperty(tb_key.Text, new JValue(panel_value.value));
                    (cur_jtok as JObject).Add(jprop);
                }
                break;
                }
            }
        }
Beispiel #2
0
        static JsonTreeViewItem addToJsonTree(JsonTreeViewItem parent_tvi, JToken jtok)
        {
            if (jtok is JObject)
            {
                JObject jobj = jtok as JObject;
                if (jobj.Parent == null)
                {
                    return(parent_tvi);
                }
                if (jobj.Parent != null && jobj.Parent is JArray)
                {
                    JsonTreeViewItem child_tvi = new JsonTreeViewItem();
                    parent_tvi.AddItem(child_tvi);
                    KeyTextBox tb_key = new KeyTextBox((jobj.Parent as JArray).IndexOf(jobj).ToString(), false);
                    child_tvi.Header.AddItem(tb_key);
                    child_tvi.value_token_type = JTokenType.Object;
                    parent_tvi = child_tvi;
                }

                //KeyTextBox tb_type = new KeyTextBox("object", false);
                //parent_tvi.Header.AddItem(tb_type);
                //parent_tvi.value_token_type = JTokenType.Object;
                //return parent_tvi;
                ValuePanel panel_value = new ValuePanel(JTokenType.Object, "object");
                parent_tvi.Header.AddItem(panel_value);
                parent_tvi.value_token_type = JTokenType.Object;
                return(parent_tvi);
            }
            else if (jtok is JProperty)
            {
                JProperty        jprop     = jtok as JProperty;
                JsonTreeViewItem child_tvi = new JsonTreeViewItem();
                parent_tvi.AddItem(child_tvi);

                KeyTextBox tb_key = new KeyTextBox(jprop.Name);
                child_tvi.Header.AddItem(tb_key);

                return(child_tvi);
            }
            else if (jtok is JValue)
            {
                JValue     jval        = jtok as JValue;
                ValuePanel panel_value = new ValuePanel(jval.Type, jval.Value);
                parent_tvi.Header.AddItem(panel_value);
                parent_tvi.value_token_type = jval.Type;

                parent_tvi.Header.addButtn.Visibility = Visibility.Hidden;
                //parent_tvi.Items.Clear();
                return(parent_tvi);
            }
            else if (jtok is JArray)
            {
                //KeyTextBox tb_type = new KeyTextBox("array", false);
                //parent_tvi.Header.AddItem(tb_type);
                //parent_tvi.value_token_type = JTokenType.Array;
                //return parent_tvi;
                ValuePanel panel_value = new ValuePanel(JTokenType.Array, "array");
                parent_tvi.Header.AddItem(panel_value);
                parent_tvi.value_token_type = JTokenType.Array;
                return(parent_tvi);
            }
            else
            {
                Log.Print("[error] undefined type = " + jtok.GetType());
                return(parent_tvi);
            }
        }