如何在数据库中持久化这个json?

如何在数据库中持久化这个json?,json,visual-studio-2010,asp.net-web-api,Json,Visual Studio 2010,Asp.net Web Api,我的Json代码如下 [ {"group":{"key":"Chinese","title":"Chinese","shortTitle":"Chinese","recipesCount":0,"description":"Chinese cuisine is any of several styles originating from regions of China, some of which have become increasingly popular in other pa

我的Json代码如下

[
    {"group":{"key":"Chinese","title":"Chinese","shortTitle":"Chinese","recipesCount":0,"description":"Chinese cuisine is any of several styles originating from regions of China, some of which have become increasingly popular in other parts of the world – from Asia to the Americas, Australia, Western Europe and Southern Africa. The history of Chinese cuisine stretches back for many centuries and produced both change from period to period and variety in what could be called traditional Chinese food, leading Chinese to pride themselves on eating a wide range of foods. Major traditions include Anhui, Cantonese, Fujian, Hunan, Jiangsu, Shandong, Szechuan, and Zhejiang cuisines. ","rank":"","backgroundImage":"images/Chinese/chinese_group_detail.png", "headerImage":"images/Chinese/chinese_group_header.png"},
    "key":1000,
    "title":"Abalone Egg Custard",
    "shortTitle" : "Abalone Egg Custard", 
    "serves":4,
    "perServing":"65kcal / 2.2g fat",
    "favorite":false,
    "rating": 3 , 
    "directions":["Step 1.","Step 2.","Step 3.","Step 4.","Step 5."],
    "backgroundImage":"images/Chinese/AbaloneEggCustard.jpg",
    "healthytips":["Tip 1","Tip 2","Tip 3"],
    "nutritions":["Calories 65kcal","Total Fat 2.2g","Carbs 4g","Cholesterol 58mg","Sodium 311mg","Dietary Fibre 0.3g"],
    "ingredients":["1 head Napa or bok choy cabbage","1/4 cup sugar","1/4 teaspoon salt","3 tablespoons white vinegar","3 green onions","1 (3-ounce) package ramen noodles with seasoning pack","1 (6-ounce) package slivered almonds","1 tablespoon sesame seeds","1/2 cup vegetable oil"]}
]

我将如何在数据库中持久化此内容?因为一天结束时,我必须从数据库中读取数据,并能够使用webapi对其进行解析,在长度可能超过varchar限制的情况下,将其作为
CLOB
数据类型保存在数据库中

这里有很多可能的答案——你需要提供更多的细节才能得到具体的答案

数据库
您使用的数据库是关系数据库、对象数据库还是sql数据库?如果您是从一个无sql的角度来看的,那么将其保存为一个整体可能是很好的。从RDBMS的角度(如SQL Server),可以将所有字段向下映射到一组相关表中的一系列行。如果您使用的是关系数据库,那么在数据库中插入未经分析、未经验证的JSON文本块是错误的做法。为什么要费心雇佣一个提供DRI的数据库呢

数据操作层
您的问题包括您将使用哪种类型的数据操作——可以是linq到sql,也可以是Direct ADO,一种像Dapper、Massive或PetaPoco这样的微型ORM,一种像实体框架或NHibernate这样成熟的ORM

您是否选择了其中一个,或者您是否正在寻找关于选择一个的指导

在WebAPI中解析 在WebApi中,从JSON转换为对象或从对象转换为JSON很容易。特别是对于JSON,JSON.Net格式化程序正在运行。您可以通过查看、和开始

然而,从概念上讲,听起来您似乎缺少了WebAPI的一部分魔力。使用WebAPI,您可以以对象的本机状态返回对象(如果需要OData支持,可以使用IQueryable)。函数调用完成后,格式化程序将接管并根据客户端请求将其序列化为正确的形状。这个过程称为内容协商。其思想是,您的方法是格式不可知的,框架将数据序列化为您的客户想要的传输格式(xml、json等)


反之亦然,框架将客户端提供的格式反序列化为本机对象。

@forsakeedsj这是一个问答网站,人们可以在这里贡献自己的空闲时间来帮助他人。获得好答案的最好方法是向志愿者展示你已经付出了一些努力。见: