c# - Why is my entire object serialized as Array when DataMember's Name is "length" -


i have created new asp.net mvc 4 web application , modified default valuescontroller this:

using system.runtime.serialization; using system.web.http;  namespace webserializationtest.controllers {     public class valuescontroller : apicontroller     {         // api/values         public apiresponse get()         {             apiresponse res = new apiresponse();             res.length = 120;             return res;         }     }      [datacontract]     public class apiresponse     {         [datamember(name = "length")]         public int length { get; set; }     } } 

now when request browser (with headers set accept: application/json), json:

[     120 ] 

however when change datamember name else, [datamember(name = "length")] correct json:

{     "length" : 120 } 

is string "length" forbidden or causing behaviour?

btw. have target framework set .net framework 4, have tried .net framework 4.5.1 , issue still there.

turns out bug in firefox's addon called restclient use.

in response body(highlight) tab json rendered incorrectly, in response body (raw) tab json correct.

i have found out known bug has not been fixed since 2012.


Comments