3

In C#, how do I serialize an object with Newtonsoft.Json.JsonConvert.SerializeObject without surrounding quotation marks around properties and their values.

Matthew Strawbridge
  • 19,940
  • 10
  • 72
  • 93
r.zarei
  • 1,261
  • 15
  • 35
  • 1
    Why would you wan to do that? It would result into invalid JSON. – Darin Dimitrov Dec 03 '11 at 14:32
  • because i use SerializeObject to generate script of highchart and in highchart property names and property values are not surrounded with quotation mark. – r.zarei Dec 03 '11 at 14:44
  • I am not familiar with highchart and its API but it seems it doesn't work with JSON because as I said quotes are required in a JSON serialized string. – Darin Dimitrov Dec 03 '11 at 14:46

1 Answers1

1

Although I agree this technically creates invalid JSON and HighCharts should happily use quoted and unquoted formats in the browser, if you really want this for some reason you can do it quite easily.

Just use the Serialize method with a JsonTextWriter and set the QuoteName property to false to prevent quotes in your property names.

https://stackoverflow.com/a/7555096/564726

BrutalDev
  • 6,181
  • 6
  • 58
  • 72