简体   繁体   English

将JSON数据发送到SQL Server 2008

[英]Send json data to SQL Server 2008

I have this problem: I receive from client-side data as json in WebApi (C#) services. 我有这个问题:我在WebApi(C#)服务中从客户端接收到的数据为json。 Data contain several data table as arrays of objects. 数据包含多个数据表作为对象数组。

I need to make change in database within one transaction (according with data received from client side). 我需要在一项事务中更改数据库(根据从客户端接收的数据)。

Which one is the best approach: 最好的方法是:

  1. send data to T-SQL as json (as string), and there to parse json and transform in hierarchy table as in article: Consuming JSON string in SQL , 将数据作为json(作为字符串)发送到T-SQL,并在那里解析json并在层次结构表中进行转换,如文章: 在SQL中使用JSON字符串

or 要么

  1. parse json in WebApi services, and then send to T-SQL one by one? 在WebApi服务中解析json,然后一一发送到T-SQL?

I think the first method is the right one. 我认为第一种方法是正确的。

I succeeded to create stored procedure with parameter json string contain multiple data table. 我成功创建了带有参数json字符串的存储过程,其中包含多个数据表。 It was simple to parse the Hierarchy table created with parseJSON (see article Consuming JSON string in SQL ). 解析使用parseJSON创建的Hierarchy表很简单(请参阅文章在SQL中使用JSON字符串 )。 According with this, I think is a good way to send multiple data table to SQL. 据此,我认为是向SQL发送多个数据表的好方法。

I want to mention: I don't have any experience with SQL Server. 我想提一提:我对SQL Server没有任何经验。 So maybe the question is stupid (was negative voted), but for me wasn't... 所以也许这个问题很愚蠢(被否决),但对我而言却不是...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM