I have a web service that has a method that looks like this
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public double[] GetUTCOffsets(string[] tzName)
{
SPTimeZone zone;
int bias;
double[] uoff = new double[tzName.Length];
int uoffCtr = 0;
DateTime today = DateTime.Now;
foreach (string tz in tzName)
{
zone = GetTZ(tzName[uoffCtr]);
bias = zone.Information.Bias;
if (!IsZero(zone.Information.DaylightDate))
{
DateTime daylightStart = ToDateTime(zone.Information.DaylightDate, today.Year);
DateTime standardStart = ToDateTime(zone.Information.StandardDate, today.Year);
if (today >= daylightStart && today < standardStart)
bias += zone.Information.DaylightBias;
}
uoff[uoffCtr++] = bias / -60.0;
}
return uoff;
}
When I try to call the web service using the ServiceProxy library (jQuery based) I get the following error
Request format is invalid: application/json.
Firebug states that this is the information that is being posted
{"tzName":["(GMT-12:00) International Date Line West","(GMT+12:00) Fiji Is., Marshall Is.","(GMT-10:00) Hawaii","(GMT-09:00) Alaska","(GMT-08:00) Pacific Time (US and Canada)","(GMT-07:00) Mountain Time (US and Canada)","(GMT-06:00) Central Time (US and Canada)","(GMT-05:00) Eastern Time (US and Canada)","(GMT) Coordinated Universal Time","(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London","(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna","(GMT+02:00) Jerusalem","(GMT+02:00) Athens, Bucharest, Istanbul","(GMT+03:00) Baghdad","(GMT+03:00) Moscow, St. Petersburg, Volgograd","(GMT+04:30) Kabul","(GMT+03:30) Tehran","(GMT+07:00) Bangkok, Hanoi, Jakarta","(GMT+08:00) Beijing, Chongqing, Hong Kong S.A.R., Urumqi","(GMT+09:00) Osaka, Sapporo, Tokyo"]}
luislebron
0 Points
2 Posts
Json problem with web service
Apr 17, 2012 06:39 PM|LINK
I have a web service that has a method that looks like this
[WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public double[] GetUTCOffsets(string[] tzName) { SPTimeZone zone; int bias; double[] uoff = new double[tzName.Length]; int uoffCtr = 0; DateTime today = DateTime.Now; foreach (string tz in tzName) { zone = GetTZ(tzName[uoffCtr]); bias = zone.Information.Bias; if (!IsZero(zone.Information.DaylightDate)) { DateTime daylightStart = ToDateTime(zone.Information.DaylightDate, today.Year); DateTime standardStart = ToDateTime(zone.Information.StandardDate, today.Year); if (today >= daylightStart && today < standardStart) bias += zone.Information.DaylightBias; } uoff[uoffCtr++] = bias / -60.0; } return uoff; }When I try to call the web service using the ServiceProxy library (jQuery based) I get the following error
Request format is invalid: application/json.
Firebug states that this is the information that is being posted
{"tzName":["(GMT-12:00) International Date Line West","(GMT+12:00) Fiji Is., Marshall Is.","(GMT-10:00) Hawaii","(GMT-09:00) Alaska","(GMT-08:00) Pacific Time (US and Canada)","(GMT-07:00) Mountain Time (US and Canada)","(GMT-06:00) Central Time (US and Canada)","(GMT-05:00) Eastern Time (US and Canada)","(GMT) Coordinated Universal Time","(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London","(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna","(GMT+02:00) Jerusalem","(GMT+02:00) Athens, Bucharest, Istanbul","(GMT+03:00) Baghdad","(GMT+03:00) Moscow, St. Petersburg, Volgograd","(GMT+04:30) Kabul","(GMT+03:30) Tehran","(GMT+07:00) Bangkok, Hanoi, Jakarta","(GMT+08:00) Beijing, Chongqing, Hong Kong S.A.R., Urumqi","(GMT+09:00) Osaka, Sapporo, Tokyo"]}BTW, the web service works on other computers.
Any ideas?
thanks,
Luis
kimkosta06
Member
270 Points
50 Posts
Re: Json problem with web service
Apr 17, 2012 06:45 PM|LINK
According to error and json sample, jason code is not valid its not parsable with deserialize method.