Convert datatable to JSON in C#

后端 未结 17 1390
猫巷女王i
猫巷女王i 2020-11-22 11:53
  1. I want to get records from database into a DataTable.
  2. Then convert the DataTable into a JSON object.
  3. Return the JSON ob
17条回答
  •  礼貌的吻别
    2020-11-22 12:40

    To access the convert datatable value in Json method follow the below steps:

    $.ajax({
            type: "POST",
            url: "/Services.asmx/YourMethodName",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                var parsed = $.parseJSON(data.d);
                $.each(parsed, function (i, jsondata) {
                $("#dividtodisplay").append("Title: " + jsondata.title + "
    " + "Latitude: " + jsondata.lat); }); }, error: function (XHR, errStatus, errorThrown) { var err = JSON.parse(XHR.responseText); errorMessage = err.Message; alert(errorMessage); } });

提交回复
热议问题