如何反序列化这个json代码并将其存储在sql中
问题描述:
{
"payload": {
"coordinators": [
{
"coordinatorID": "1",
"remarks": "a",
"briefObservation": "a",
"justifyingRecommendation": "a",
"sectors": [
{
"sectorNumber": "8",
"projectDescription": "a",
"knowledgeMarks": "a",
"siteMarks": "a",
"impactAccessmentMarks": "a",
"empAddressingMarks": "a",
"totalMarks": "a",
"recommendation": "a",
"category": "a"
},
{
"sectorNumber": "10",
"projectDescription": "a",
"knowledgeMarks": "a",
"siteMarks": "a",
"impactAccessmentMarks": "a",
"empAddressingMarks": "a",
"totalMarks": "a",
"recommendation": "a",
"category": "a"
}
]
}
]
},
"status": 0,
"message": "Success/Fail Reason"
}
答
Json.NET是你的朋友。您可以直接在文档中找到示例。
http://www.newtonsoft.com/json/help/html/SerializingJSON.htm
“在SQL存储它” 是一个有点普通。如果不知道有问题的数据库或比标签“C#”更多的实现目标,我只能猜测。这里有另一个Youtube视频教程的链接 - 连接到MySQL数据库并用C#插入数据。
首先,[deserielize](http://www.newtonsoft.com/json/help/html/DeserializeObject.htm),然后[插入到您的SQL服务器](http://stackoverflow.com/questions/8389803 /插入数据 - 到 - SQL服务器数据库)。你有很多选择来做这些操作。这只是一个例子。 – KernelMode
您正在使用哪个版本的SQL服务器?或者你在使用不同的数据库? –
要获得反序列化的C#类,请在[json2csharp.com](http://json2csharp.com/)中输入json文本,然后单击“generate”。 – Graffito