Ejemplo n.º 1
0
        void ToEscapeChars()
        {
            var txt = RequestDocument["txt"].ToString();


            try
            {
                var jsonStringData = RichTextBoxHelper.CompressJsonString(txt);

                //因为引号使用了反斜杠\ , 所以先操作反斜杠\  再操作引号
                // 如果先操作引号的话, 那引号转义后产生的反斜杠\再转义将会产生更多的反斜杠\
                string str = jsonStringData.Replace("\\", "\\\\").Replace("\"", "\\\"");

                //rpc调用(包括网站)
                var jd = new JsonData()
                {
                    ["txt"] = string.Empty
                };
                if (!string.IsNullOrEmpty(str))
                {
                    jd["txt"] = str;
                }

                Json((int)ReturnStatus_Ext.Success, string.Empty, jd);
            }
            catch (Exception exception)
            {
                Json((int)ReturnStatus_Ext.ServerError, exception.Message);
            }
        }
Ejemplo n.º 2
0
        private void btnCompressEscapeChars_Click(object sender, EventArgs e)
        {
            try
            {
                var jsonStringData = RichTextBoxHelper.CompressJsonString(textBox.Text);

                //因为引号使用了反斜杠\ , 所以先操作反斜杠\  再操作引号
                // 如果先操作引号的话, 那引号转义后产生的反斜杠\再转义将会产生更多的反斜杠\
                string str = jsonStringData.Replace("\\", "\\\\").Replace("\"", "\\\"");
                textBox.Text = str;
                btnCompressEscapeChars.Visible = false;
            }
            catch (Exception exception)
            {
                this.ShowException(exception);
            }
        }