【问题标题】:How to Store Json data into Sql table in asp.net如何将 Json 数据存储到 asp.net 中的 Sql 表中
【发布时间】:2012-08-29 18:40:07
【问题描述】:

我想使用 Jquery 和 Ajax 将 Json 数据存储到表中。这是我的 Json 文件如下所示:-

[
{
"term": "BACCHUS",
"part": "n.",
"definition": "A convenient deity invented by the ancients as an excuse for getting drunk.",
"quote": [
"Is public worship, then, a sin,",
"That for devotions paid to Bacchus",
"The lictors dare to run us in,",
"And resolutely thump and whack us?"
],
"author": "Jorace"
},
{
"term": "BACKBITE",
"part": "v.t.",
"definition": "To speak of a man as you find him when he can't find you."
},
{
"term": "BEARD",
"part": "n.",
"definition": "The hair that is commonly cut off by those who justly execrate the absurd Chinese custom of shaving the head."
}
]

我有一个名为“json”的表,其中三列的名称分别为术语、部分和定义。现在我刚刚像这样将 json 数据加载到 html 表中。

   $.ajax({
        type: "GET",
        url: "b.json",
        dataType: "json",
        success: function (data) {
            $.each(data, function (entryIndex, entry) {
                //   var html = '<div class="declareing_variable">';
                var html1 = entry['term'];
                var html2 = '<div class="geting_part">' + entry['part'] + '</div>';
                var html3 = '<div class="geting_definition">' + entry['definition'] + '</div>';
                $('<tr></tr>').html('<th>' + html1 + '</th><th>$' + html2 + '</td><th>$' + html3 + '</th>').appendTo('#json');
                $('#abc').append(html2);

            });
        }
    });

谁能告诉我如何将它存储到 sql 表中并可以提供一些编码帮助?

【问题讨论】:

  • jQuery 不与数据库对话。而且 b.json 不太可能是真正的 url。你需要一种像 PHP 这样的语言来做到这一点。
  • 实际上在asp.net C#项目中需要它。我希望我们可以在C#中做到这一点。 btw b.json 文件直接放在 current 中。
  • 您需要再发送一个带有所需数据的 ajax 请求,因为 jQuery 无法直接与服务器通信。然后,您需要使用 sql 查询或存储过程将这些数据存储到数据库中。

标签: c# jquery asp.net json mysql


【解决方案1】:

您的服务器端编程语言是什么?

如果是 PHP,您可以使用 JSON_DECODE() 来解码您发送到 Web 服务器的 json 数据:json_decode() on PHP website

但是,由于您使用的是 C#,因此您需要使用 this JSON Library on Codeplex 之类的东西来解码您的 JSON。

【讨论】:

    猜你喜欢
    • 2021-07-03
    • 2020-02-04
    • 1970-01-01
    • 1970-01-01
    • 2022-07-26
    • 2023-03-20
    • 2019-01-11
    • 1970-01-01
    • 2018-12-03
    相关资源
    最近更新 更多