如何提取DataSet中的DataTable这是JSON格式 [英] How to extract DataTable from DataSet which is in JSON format
本文介绍了如何提取DataSet中的DataTable这是JSON格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Newtonsoft DLL进行序列化。我目前JSON格式返回从数据表中的WebMethod。并能正常工作。但我想通过返回,而不是一个DataTable的DataSet做同样的事情。我尝试了一些东西,但没有似乎工作。
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中返回:
[{名:山姆,ID:1},{名:标志,ID:2}]
的Json数据集返回的:
{"patients":[{"name":"sam","id":"1"},{"name":"mark","id":"2"}],"medications":[{"id":"1","medication":"atenolol"},{"id":"2","medication":"amoxicillin"}]}
小提琴
演示
VAR JSON = jsonds ['病人'];
与 VAR JSON =数据['病人'];
推荐答案
最后,我成功了。
在阿贾克斯
的成功的,做像下面...
Inside Ajax
Success, do like below...
var dataSet = jQuery.parseJSON(data.d);
var dataTable = dataSet["patients"];
$.each(dataTable, function () {
myDropDownList.append($("<option></option>").val(this['id']).html(this['name']));
});
这篇关于如何提取DataSet中的DataTable这是JSON格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文