Answered by:
Wrap JSON data with callback function?

Question
-
User48651432 posted
I have a WCF service that returns a JSON object. Is there an easy way of wrapping this JSON data in parentheses and add the callback name?
I tried something like the following, but the result is surrounded by double-quotes:
Dim serializer as New JavaScriptSerializer() Dim arrayJson as String = serializer.Serialize(myArray)
Currently, it returns this:
[ { "val1": "GWh", "val2": 32203, "val3": "2008" }, { "val1": "GWh", "val2": 27568, "val3": "2007" } ]
It needs to return this with the callback and the parenthesis:
callback([ { "val1": "GWh", "val2": 32203, "val3": "2008" }, { "val1": "GWh", "val2": 27568, "val3": "2007" } ])
I'm using VS2010 and framework 4.0.
Thanks.
Thursday, July 11, 2013 3:16 PM
Answers
-
User48651432 posted
Never mind, return it as a stream. This causes the "raw" mode to be used and WCF will not touch the response.
Link: http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-web.aspx.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, July 12, 2013 9:20 AM
All replies
-
User48651432 posted
Never mind, return it as a stream. This causes the "raw" mode to be used and WCF will not touch the response.
Link: http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-web.aspx.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, July 12, 2013 9:20 AM -
User260886948 posted
Hi,
I am very glad that you have solved your problem by yourself.
If you have any other problem, welcome to post your question in asp.net forums.
Best Regards,
Amy PengMonday, July 15, 2013 1:38 AM -
User48651432 posted
Lately, I've posted several questions that I end up answering myself. Since I assume it's because no other expert knows the answer, do I get the points?
Wednesday, July 17, 2013 10:55 AM -
User260886948 posted
Hi,
Yes, in my mind, you are right.
Best Regards,
Amy PengWednesday, July 17, 2013 10:22 PM