Menu
  • HOME
  • TAGS

Avoiding CamelCasePropertyNamesContractResolver for a specific method

c#,asp.net-web-api,json.net,camelcasing,datacontractjsonserialize

you can use ApiController.Json method. just return like this from your controller method return Json(data, new JsonSerializerSettings(){ContractResolver = new DefaultContractResolver()}); ...

Using DataContractJsonSerializer to create a Non XML Json file

c#,json,serialization,datacontractjsonserialize

Assuming you're just trying to write the text to a file, it's not clear why you're writing it to a MemoryStream first. You can just use: var js = new DataContractJsonSerializer(typeof(T), _knownTypes); using (var stream = File.Create(path)) { js.WriteObject(stream, item); } That's rather simpler, and should do what you want......

There was an error deserializing the object of type RD.Details. '�19.95 Per Person' contains invalid UTF8 bytes

c#,.net,json,serialization,datacontractjsonserialize

Turns out it was just a simple thing of changing the encoding line to buffer = Encoding.UTF8.GetBytes(serializedString); ...

Using DataContractJsonSerializer, deserialization of JSON string into C# object which has list & interface as properties

c#,json,rest,serialization,datacontractjsonserialize

Since none of your classes are actually polymorphic, there are a couple solutions available that use .Net built-in class libraries: Solution 1: JavaScriptSerializer Solution JavaScriptSerializer makes it easy to remap interfaces to classes during deserialization by using a JavaScriptConverter. However, it does not allow field and property names to be...