コード例 #1
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            txtOutput.Text = string.Empty;
            var result = validateWindow();

            if (!string.IsNullOrEmpty(result))
            {
                MessageBox.Show(result, APPLICATION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            try
            {
                JsonPathModel model = new JsonPathModel
                {
                    SourceJson  = string.Join(Environment.NewLine, txtJson.Lines),
                    Expressions = Array.ConvertAll(txtExpression.Text.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries), (s) => new JsonPathExpression {
                        Expression = s
                    })
                };

                var expressions = _presenter.ParseExpression(model);

                foreach (var expression in expressions)
                {
                    if (!isFirstLine())
                    {
                        txtOutput.Text += Environment.NewLine + Environment.NewLine;
                    }

                    var nodes = expression.Nodes.Select(node => new { Path  = node.Path,
                                                                      Value = JsonConvert.Serialize(node.Value) });

                    txtOutput.Text += string.Format("Output of {0} is: \r\n {1}\r\n", expression.Expression,
                                                    string.Join(Environment.NewLine + Environment.NewLine, nodes));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, APPLICATION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }