我有一个名为的javascript对象concept:
function concept() {
this.ConceptId = 0;
this.Name = "";
}
Run Code Online (Sandbox Code Playgroud)
我试图在jQuery中启动它document.ready:
$(document).ready(function() {
var concept = new concept;
});
Run Code Online (Sandbox Code Playgroud)
它返回一个错误:
未捕获的TypeError:概念不是构造函数
如果我将对象移到其中document.ready,它就可以工作了.
$(document).ready(function() {
function concept() {
this.ConceptId = 0;
this.Name = "";
}
var concept = new concept;
});
Run Code Online (Sandbox Code Playgroud)
我仍然是javascript的新手,据我所知,document.ready在DOM完成时运行.我不明白为什么它无法访问document.ready范围外定义的对象.
我只是在尝试为我的单元测试构建一个json字符串,并且意外地,以下代码返回系统格式异常。错误消息表明它正在尝试解析日期,这对我来说很奇怪。我不是要解析日期。
class Program
{
static void Main(string[] args)
{
Console.WriteLine(GetJson());
Console.ReadKey();
}
static string GetJson(string dateStr = "", string lta = "5.25")
{
return String.Format("[{\"dateBooking\":\"{0}\",\"lta\":\"{1}\"}]", dateStr, lta);
}
}
Run Code Online (Sandbox Code Playgroud)
可以很容易地复制它,但是我要添加异常详细信息:
“ mscorlib.dll中发生了类型为'System.FormatException'的未处理的异常
其他信息:输入字符串的格式不正确。”
我想创建WCF Restful服务,它将Complex Type作为Json格式的参数并返回Json.我阅读了很多文章并在网上查看了很多样本.有些文章建议在Endpoint行为中添加标签并装饰Service方法,如下所示,
[WebInvoke(UriTemplate = "/PlaceOrder",
RequestFormat= WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json, Method = "POST")]
Run Code Online (Sandbox Code Playgroud)
在这种情况下,WCF返回"Endpoints using 'UriTemplate' cannot be used with 'System.ServiceModel.Description.WebScriptEnablingBehavior'."错误消息.
另一种建议的方式(如本文http://dotnetmentors.com/wcf/wcf-rest-service-to-get-or-post-json-data-and-retrieve-json-data-with-datacontract.aspx)将""标记添加到Endpoint行为而不是.但在这种情况下IIS返回("远程服务器返回错误:(400)错误请求.")错误消息.
你能帮我解决一下如何创建Restful Service,它采用json格式的复杂类型参数并返回json.