使用MVC2从外部服务器接收JSON,解析它并将其保存到本地数据库
我需要构建一个 MVC2 项目,它可以接收从外部服务器发送的 JSON ({"Address":"Streetname","Age":42"})
,解析它并将其保存到我的本地数据库(也许在模型的帮助下?)。
因为我以前从未这样做过,所以我不确定如何处理它,我需要一些关于在这种情况下推荐哪种技术的指示(Linq to sql,实体框架、ADO.NET 实体框架)以及如何接收 JSON 字符串(ActionMethod,或者可能在控制器中?)并将其保存在本地(在接收时自动保存),
我将不胜感激 。没有太多时间阅读所有初学者教程。
I need to build a MVC2 project that can receive JSON ({"Address":"Streetname","Age":42"})
which is sent from an external server, parse it and save it to my local database (maybe with the help of a model?).
As I have never done this before, I am unsure about how to handle it. I would need some pointers about which technique it is recommended in this case (Linq to sql, Entity Framework, ADO.NET Entity Framework) and how to receive the JSON string (ActionMethod, or maybe in the Controller?) and save it localy (automatically, on receive).
Links to right documentation would be much appreciated, as I don't have a lot of time to read through all the beginners' tutorials.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您确实正在寻找超级简单的东西,那么如果您使用 MVC 3,它就可以像这样简单,它内置了用于控制器操作参数的 JSON 模型绑定。
我在本例中使用 LinqToSql。除非您开始拥有领域逻辑或更复杂的实体,否则它确实是您所需要的。
对于 MVC 2,您需要下载 Futures 库并将其添加到您的应用程序启动中。
您可以找到详细信息 这里。
If you're really looking for something super simple, it can be as easy as this if you use MVC 3, which has built in JSON model binding for controller action parameters.
I'm using LinqToSql in this example. Unless you start having domain logic or more complex entities it's really all you need.
For MVC 2, you need to download the Futures library and add this to your application startup.
You can find details here.