如何从DataSet中提取JSON格式的DataTable。 [英] How to extract DataTable from DataSet which is in JSON format.

查看:207
本文介绍了如何从DataSet中提取JSON格式的DataTable。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Newtonsoft DLL进行序列化。我目前正在以json格式从webmethod返回DataTable。它工作正常。但我希望通过返回DataSet而不是DataTable来做同样的事情。我尝试了很多东西,但似乎没有工作。



I am using Newtonsoft dll for serialization. I am currently returning DataTable from webmethod in Json Format. And it works fine. But I want to do the same thing by returning DataSet instead of a DataTable. I tried a number of things but none seem to be working.

function GetDropDownData() {
        var myDropDownList = $('.myDropDownLisTId');

        $.ajax({
            type: "POST",
            url: "test.aspx/GetDropDownDataWM",
            data: '{name: "abc" }',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                $.each(jQuery.parseJSON(data.d), function () {
                    myDropDownList.append($("<option></option>").val(this['id']).html(this['name']));
                });
            },
            failure: function (response) {
                alert(response.d);
            }
        });
    }
    function OnSuccess(response) {
        console.log(response.d);
        alert(response.d);
    }







Json DataTable Returned:

[{"name":"sam","id":"1"},{"name":"mark","id":"2"}]

Json DataSet Returned:

 {"patients":[{"name":"sam","id":"1"},{"name":"mark","id":"2"}],"medications":[{"id":"1","medication":"atenolol"},{"id":"2","medication":"amoxicillin"}]}







我正在使用NewtonSoft dll序列化

我的webmethod使用此代码返回Json




I am using NewtonSoft dll to serialize
My webmethod returns Json usingthis code

return JsonConvert.SerializeObject(set);

推荐答案

' .myDropDownLisTId');


.ajax({
type: < span class =code-string> POST,
url: test.aspx / GetDropDownDataWM
data:' {name:abc}'
contentType: application / json; charset = utf-8
dataType: json
成功: function (data){
.ajax({ type: "POST", url: "test.aspx/GetDropDownDataWM", data: '{name: "abc" }', contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) {


.each(jQuery.parseJSON(data.d), function ( ){
myDropDownList.append(
.each(jQuery.parseJSON(data.d), function () { myDropDownList.append(


这篇关于如何从DataSet中提取JSON格式的DataTable。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆