0

I have a question, we are converting asp.net 3.5 to asp.net 4.5 during this - we had many problems but now... we finally got it too load up now i am having strange behaviour in JSON responses from services they don't contain "d" anymore!

{d: "response from server"}

its now

{"response from server"}

which breaks javascript code for callback any idea? or explanation

Rizwan Ahmed
  • 470
  • 1
  • 5
  • 10
  • Can you provide a sample application which reproduces this behavior? This behavior shouldn't have changed between 3.5 and 4.5, and I cannot repro it on my own box. – Levi Aug 16 '13 at 22:41
  • Here is the 4.5 Solution - You will see that there is no result.d there. You can download it here http://sdrv.ms/19z7O3q – Rizwan Ahmed Aug 17 '13 at 01:32
  • the behavior still appears to be correct on our machines. (MS AJAX has always unwrapped the "d" parameter before invoking the callback.) Did anything else change in the project when you upgraded from 3.5 to 4.5? For instance, did you take a dependency on a new JavaScript library or on a different version of an existing library? – Levi Aug 19 '13 at 16:29

2 Answers2

0

The behavior has changed, because Microsoft switched from using the DataContractJsonSerializer to Json.NET (NewtonSoft).

Karl Anderson
  • 34,606
  • 12
  • 65
  • 80
  • No I am using Asp.net Ajax in asp.net 4.5. I want to know the reason why its behavior has changed from earlier version 3.5 – Rizwan Ahmed Aug 16 '13 at 20:28
-1

If you want to name your variable when you return a result, you need to serialize it properly.

If you return a string you will get { "your string" } but if you return an object (or in 4.5 a Task of type dynamic or better yet Task of type 'Your Object') you will get your fully serialized object

return new { 
   result = "here is your result", 
   code  = "here is your code"
}
Matthew
  • 411
  • 4
  • 14