如何在C#Web服务中获取json数据? [英] How to get the json data in C# web service?

查看:247
本文介绍了如何在C#Web服务中获取json数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#和SQL Server中使用带有存储过程的Web服务。 Web服务代码采用XML格式。我需要将代码转换为JSON格式以便在AngularJs中使用。或者是否有可能以JSON格式返回Web服务数据?



我尝试过:



这是我的输出



I'm using a web service in C# and SQL Server with a stored procedure. The web service code is in the XML format. I need to convert the code to JSON format for using in AngularJs. Or is there any possibility to return the web service data in JSON format?

What I have tried:

This is my Output

<NewDataSet> 
      <Table> 
        <iDept_category_id>6</iDept_category_id> 
        <cDept_category>qaz</cDept_category> 
        <dcreate_dt>01 Jan 2016</dcreate_dt> 
      </Table> 
      <Table> 
        <iDept_category_id>7</iDept_category_id> 
        <cDept_category>ICU</cDept_category> 
        <dcreate_dt>01 Dec 2016</dcreate_dt> 
      </Table> 
   </NewDataSet>





我需要此输出 < br $>


{NewDataSet:

{表:[

{

iDept_category_id:6,

cDept_category:qaz,

dcreate_dt:2016年1月1日< br $>
},

{

iDept_category_id:7,

cDept_category:ICU,

dcreate_dt:2016年12月1日

}

]}

}



I need this output in

{"NewDataSet":
{"Table":[
{
"iDept_category_id":"6",
"cDept_category":"qaz",
"dcreate_dt":"01 Jan 2016"
},
{
"iDept_category_id":"7",
"cDept_category":"ICU",
"dcreate_dt":"01 Dec 2016"
}
]}
}

推荐答案

XML 转换为 JSON 是一项常见任务,您可以在网上找到很多材料。例如,请参阅: c# - 如何将JSON转换为XML或XML到JSON? - 堆栈溢出 [ ^ ]。
Converting from XML to JSON is a common task, you may find a lot of material on the web. See, for instance: c# - How to convert JSON to XML or XML to JSON? - Stack Overflow[^].


这篇关于如何在C#Web服务中获取json数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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