使用从WCF数据服务的服务操作返回的复杂数据json的问题 [英] Issue in using the complex data json returned via service operation from WCF Data service
问题描述
我试图通过我的WCF数据服务的服务操作返回IEnumerable。该操作在浏览器中运行良好并返回json。但是,当我通过jQuery在我的客户端应用程序中使用它时,firefox错误控制台提供了json格式的错误。
I am trying to return an IEnumerable via my service operation of WCF Data service. The operation runs fine in browser and returns json. However when I consume it in my client app via jQuery, firefox error console gives and error in json format.
Below is my code to return complex data: 您能告诉我们您用于获取结果的代码吗? ,你正在使用哪个版本的jQuery? Can you show us the code you're using to get the results, and which version of jQuery you are using? 如果你正在使用jQuery来获取OData,我可能还建议使用 If you're using jQuery just to get to OData, I might also suggest using
http://datajs.codeplex.com/, which provides some more specialized functionality. 这篇关于使用从WCF数据服务的服务操作返回的复杂数据json的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
以下是我返回复杂数据的代码:
[WebGet]
public IEnumberable<ComplexType> GetNames()
{
return (this.CurrentdataSource.UserNames
.Select(x => new {
ID = x.ID,
Name = x.Name
}).ToList()
.Select(x => new ComplexType {
ID = x.ID,
Name = x.Name
}));
}
推荐答案
http://datajs.codeplex.com/ ,它提供了一些更专业的功能。