Hi
I have been browsing the web for two days to find a solution for this issue, including this forum, and I could not find the solution.
I have built a WCF Restful Service based on an example, which returned a "valid json response", but not.
The first attempt was to serialize an object and then return it.
The result was a string that looked like json but which was in fact a string containing the json information:
"{jasonstring}"
This obviously did not work.
The way to detect it is to inspect the client-page in the browser, and look in the network tab, where the json output is printed.
The second attempt was to get rid of the outer-quotes.
In several discussions on the web it is recommended to serialize the object, and to stream it (defining the object as void) instead of returning it as a string. The quotes are gone, and json/validation sites do qualify the output as valid.
Nevertheless my Kendo grid did not populate.
The third attempt was to get rid of the streaming, based upon a discussion on stackoverflow (http://stackoverflow.com/questions/2086666/wcf-how-do-i-return-clean-json).
The advice in this discussion is to return the object as such, without any manipulation.
As long as the output of the webmethod is defined as json, ASP.NET will create a json string from the object,
And this worked.
example from the thread:
I hope that this thread will help all of you to find your solution earlier than I did.
KR
Henk Jelt
I have been browsing the web for two days to find a solution for this issue, including this forum, and I could not find the solution.
I have built a WCF Restful Service based on an example, which returned a "valid json response", but not.
The first attempt was to serialize an object and then return it.
The result was a string that looked like json but which was in fact a string containing the json information:
"{jasonstring}"
This obviously did not work.
The way to detect it is to inspect the client-page in the browser, and look in the network tab, where the json output is printed.
The second attempt was to get rid of the outer-quotes.
In several discussions on the web it is recommended to serialize the object, and to stream it (defining the object as void) instead of returning it as a string. The quotes are gone, and json/validation sites do qualify the output as valid.
Nevertheless my Kendo grid did not populate.
The third attempt was to get rid of the streaming, based upon a discussion on stackoverflow (http://stackoverflow.com/questions/2086666/wcf-how-do-i-return-clean-json).
The advice in this discussion is to return the object as such, without any manipulation.
As long as the output of the webmethod is defined as json, ASP.NET will create a json string from the object,
And this worked.
example from the thread:
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "players")]
public List<Person> GetPlayers()
{
List<Person> players = new List<Person>();
players.Add(new Person { FirstName="Peyton", LastName="Manning", Age=35 } );
players.Add(new Person { FirstName="Drew", LastName="Brees", Age=31 } );
players.Add(new Person { FirstName="Brett", LastName="Favre", Age=58 } );
return players;
}
I hope that this thread will help all of you to find your solution earlier than I did.
KR
Henk Jelt