使用web api处理json结果的最佳实践 [英] Best practice on working with json results from web api
问题描述
大家好,感谢您查看我的问题。
我将首先澄清我不是.NET开发人员,我只是知道得到这么多道歉如果这是一个简单的问题。
我是数据仓库/ BI开发人员,当我们需要访问来自第三方的数据时,我们通常会获得他们的访问权限。 "&的RESTful QUOT;返回json数据的web API(相当小的公司没有专门的.NET
开发人员)。这很好,我能够将这些数据插入SQL Server,我只觉得必须有更好的方法。
我的一般方法是:
- 调用Web服务并将结果反序列化为类json结构的设置。
- 遍历第一步中生成的列表并构建一个insert语句,一次一条记录插入数据库。
- 继续调用Web服务,重复步骤2,直到我检索并插入所有记录。
我是否会更好地将记录添加到像数据表这样的东西并在我达到一定数量时进行批量插入行?反序列化为一个大的对象列表是一个好主意的想法吗?
我当前的解决方案是有效的,但它只是一个"只是让它工作"解决方案而不是这是实现这一目标的最佳方式。也许有人可以指出我对这类事情的一般/推荐设计模式的方向。
提前致谢
Mark
以下论坛是您应该发布的地方。
http://forums.asp达网络/ 1246.aspx / 1?的Web + API
Hi all, Thanks for looking at my question.
I will start with clarifying that I am not a .NET developer, I just know enough to get by so apologies if this is a simple question.
I am a data warehouse/BI developer and more often than not these days when we require access to data from a third party we are usually given access to their "RESTful" web APIs which return json data (quite a small company with no dedicated .NET developer). This is all fine and I am able to insert this data into SQL Server, I just feel there has to be a better way.
My general approach is to:
- Call the web service and deserialize the results into a class setup for the json structure.
- Loop through the list generated in step one and build an insert statement to insert into the database one record at a time.
- Keep calling the web service and repeating step 2 until I have retrieved and inserted all records.
Would I be better off adding records to something like a datatable and doing a bulk insert when I hit a certain number of rows? Is deserializing into a big list of objects a good idea with performance in mind?
My current solution works however it's been a bit of a "just make it work" solution rather than this is the best way to achieve this. Perhaps someone could point me in the direction of a general/recommended design pattern for this sort of thing.
Thanks in advance
Mark
The below forum is where you should post.
http://forums.asp.net/1246.aspx/1?Web+API
这篇关于使用web api处理json结果的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!