在同一存储过程的JSON输出中复制存储过程的现有XML输出 [英] Replicate existing XML Output of Stored Proc in JSON output of the same Stored Proc

查看:70
本文介绍了在同一存储过程的JSON输出中复制存储过程的现有XML输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Visual Studio的整个世界都很陌生。这可能更适合在不同的论坛,所以如果是这样,请告诉我。谢谢。

I am quite new to the whole world of Visual Studio. This may be more appropriate in a different forum, so please let me know if that is the case. Thanks.

我被要求复制一个现有的.net页面,它将存储过程中的结果集导出为xml,除了他们现在想要的它是  JSON。

I have been asked to replicate an existing .net page which exports the resultset from a Stored Proc as xml, except they now want it as JSON.

以下是执行此操作的页面背后的现有代码:

Here's the existing code behind for the page that does this:

使用System;

使用System.Collections.Generic;

使用System.Linq;

使用System.Web;

使用System.Web.UI;

使用System.Web.UI.WebControls;

使用System.Text;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

命名空间WebApplicationXXX

{

    public partial class CertifiedEquipmentXML:System.Web.UI.Page

    {

        protected void Page_Load(object sender,EventArgs e)

        {

            StringBuilder sb = new StringBuilder();

            sb.Append(@"<?xml version ="" 1.0"" encoding ="" UTF-8""?>");

  ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; sb.Append("< Equipment>");&
            sb.Append(DataAccess.CertifiedEquipmentXML());

            sb.Append("< / Equipment>");&
            Response.ContentType =" text / xml";

            Response.Write(sb.ToString());

           到Response.End(); //所以html没有呈现

        }
    } b $ b}

namespace WebApplicationXXX
{
    public partial class CertifiedEquipmentXML : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
            sb.Append("<Equipment>");
            sb.Append(DataAccess.CertifiedEquipmentXML ());
            sb.Append("</Equipment>");
            Response.ContentType = "text/xml";
            Response.Write(sb.ToString());
            Response.End(); //so the html is not rendered
        }
    }
}

以下是生成XML的相关公共方法:

And here is the relevant public method that generates the XML:

        public static string getCertifiedBaseballBatsXML()

        {

            string sqlResult = string.Empty;

           使用(SqlConnection conn = new SqlConnection(settings.ConnectionString))

            {

        public static string getCertifiedBaseballBatsXML()
        {
            string sqlResult = string.Empty;
            using (SqlConnection conn = new SqlConnection(settings.ConnectionString))
            {

                string sql = @" proc_getCertifiedEquipmentXML"; 


               使用(的SqlCommand CMD =新的SqlCommand(SQL,康涅狄格州))

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; cmd.CommandType = System.Data.CommandType.StoredProcedure;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP; conn.Open();&
                   &NBSP;使用(的XmlReader读取器= cmd.ExecuteXmlReader())

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP; {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP; while(reader.Read())

                  &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; SQLRESULT + = reader.ReadOuterXml();

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; //使用s做
                   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP; }

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; }
                }
            }
            return sqlResult;

        }

                string sql = @"proc_getCertifiedEquipmentXML"; 
                using (SqlCommand cmd = new SqlCommand(sql, conn))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    conn.Open();
                    using (XmlReader reader = cmd.ExecuteXmlReader())
                    {
                        while (reader.Read())
                        {
                            sqlResult += reader.ReadOuterXml();
                            // do something with s
                        }
                    }
                }
            }
            return sqlResult;
        }

结果是一个带有XML的页面

The result is a page with the XML

我所要求的是,如上所述,用JSON输出复制它。我不知道该怎么办。提前感谢您提供的任何帮助。

What I've been asked to do is, as noted, replicate it with JSON output. I have no idea how to proceed. thanks in advance for any assistance you can offer.

George

用Joy Wend Your Way

With Joy Wend Your Way

推荐答案



嗨George Hepworth,


Hi George Hepworth,

此论坛正在讨论Visual Studio WPF / SL Designer,Visual Studio Guidance Automation Toolkit,开发人员文档和帮助系统以及Visual Studio编辑器。

This forum is discussing Visual Studio WPF/SL Designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System, and Visual Studio Editor.

您的问题与ASP.NET开发有关,我认为您应该将此帖子重新发布到以下网站以获得专业答案,非常感谢:

Your issue is related to ASP.NET development, I think you should re-post this thread to the following site for a professional answer, thank you very much:

http://forums.asp.net/15.aspx/1 ?获取+开始

此致,

奥斯卡


这篇关于在同一存储过程的JSON输出中复制存储过程的现有XML输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆