我有一个JSON列出了数据库中的值。以下是数据库中2行的JSON数据。如何将数据库值附加到JSON数据
[{"Name":"P1","Description":"pd1","Value":"v1","Attribute":"a1"},{"Name":"P1","Description":"pd1","Value":"v2","Attribute":"a2"}]
数据库值是左连接查询的结果。只有'价值'和'属性'字段是不同的。我可以将这些字段附加到JSON而不是多组记录吗?我知道有'推'来做到这一点,但我不知道在我的代码中如何以及如何使用它。下面是从db中获取值并序列化值的代码。
GetProfileDataService GetProfileDataService = new BokingEngine.MasterDataService.GetProfileDataService();
IEnumerable<ProfileData> ProfileDetails = GetProfileDataService.GetList(new ProfileSearchCriteria { Name = strProfileName });
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
string strSerProfileDetails = javaScriptSerializer.Serialize(ProfileDetails);
context.Response.ContentType = "text/json";
context.Response.Write(strSerProfileDetails);
下面是我的getJSON
$(document).ready(function() {
$.getJSON('ProfileHandler.ashx', { 'ProfileName': 'Profile 1' }, function (data) {
$.each(data, function (k, v) {
alert(v.Attribute+' : '+v.Value);
});
});
});
请帮我在这里。
你100%肯定上面的代码实际上是JavaScript的? Javascript不是强类型的... – 2013-03-11 10:33:29
上面的代码不是Javascript。上面的代码会将JSON数据返回给getJSON ajax方法 – Sandy 2013-03-11 10:38:36
对不起,我没有正确阅读它。我的错。 – 2013-03-11 10:52:42