我使用AJAX & WCF
并且我想发送一个数组KeyValuePair
:
服务中的数组(即在特定类中):
[DataMember]
public KeyValuePair<string, CustomDay>[] WorkDays { get; set; }
CustomDay.cs:
[DataContract]
public class CustomDay
{
[DataMember]
public CustomTime Start { get; set; }
[DataMember]
public CustomTime End { get; set; }
}
自定义时间.cs:
[DataContract]
public class CustomTime
{
[DataMember]
public int Hour { get; set; }
[DataMember]
public int Minute { get; set; }
}
JavaScript
我通过以下函数创建数组:
function CreateWorkDaysDictonary() {
var workdaysdic = new Object();
if ($('#checkbox-sunday').is(':checked')) {
var starttime = { Hour: $('#select-from-hour-sunday').val(),
Minute: $('#select-from-minute-sunday').val()
};
var endtime = { Hour: $('#select-until-hour-sunday').val(),
Minute: $('#select-until-minute-sunday').val()
};
workdaysdic["Sunday"] = { Start: starttime, End: endtime };
}
if ($('#checkbox-monday').is(':checked')) {
var starttime = { Hour: $('#select-from-hour-monday').val(),
Minute: $('#select-from-minute-monday').val()
};
var endtime = { Hour: $('#select-until-hour-monday').val(),
Minute: $('#select-until-minute-monday').val()
};
workdaysdic["Monday"] = { Start: starttime, End: endtime };
}
//and so on...
return workdaysdic;
}
数组创建于JS
:
但是WCF
数组到达时没有数据:
我不明白为什么会发生这种情况,我会很高兴有人可以帮助我。
我将对象发送到 WCF JSON
:
当我尝试创建对象时喜欢这样:
function CreateWorkDaysDictonary() {
var workdaysdic = new Array();
if ($('#checkbox-sunday').is(':checked')) {
var starttime = { Hour: $('#select-from-hour-sunday').val(),
Minute: $('#select-from-minute-sunday').val()
};
var endtime = { Hour: $('#select-until-hour-sunday').val(),
Minute: $('#select-until-minute-sunday').val()
};
workdaysdic[workdaysdic.length] = { "Sunday": { Start: starttime, End: endtime}};
}
if ($('#checkbox-monday').is(':checked')) {
var starttime = { Hour: $('#select-from-hour-monday').val(),
Minute: $('#select-from-minute-monday').val()
};
var endtime = { Hour: $('#select-until-hour-monday').val(),
Minute: $('#select-until-minute-monday').val()
};
workdaysdic[workdaysdic.length] = { "Monday": { Start: starttime, End: endtime} };
}
//and so on...
return workdaysdic;
}
我得到错误:the server responded with a status of 400 (Bad Request)