I'm writing a tool to read JSON files. I'm using the NewtonSoft tool to deserialize the JSOn to a C# class. Here's an example fragment:
"name": "Fubar",
".NET version": "4.0",
"binding type": "HTTP",
The field names contain spaces and other characters (the .) that are invalid in C# identifiers. What is the correct way to do this?
(Unfortunately I don't have the option of changing the JSON format.)
Whitespace (Space, Horizontal tab, Line feed or New line or Carriage return) does not matter in JSON. It can also be minified with no affect to the data. Object literal names MUST be lowercase (ie – null, false, true etc). Keep all name and value pairs in quotes to aviod.
JSON is a format that encodes objects in a string. Serialization means to convert an object into that string, and deserialization is its inverse operation (convert string -> object).
JSON is a format that encodes an object to a string. On the transmission of data or storing is a file, data need to be in byte strings, but as complex objects are in JSON format. Serialization converts these objects into byte strings which is JSON serialization.
The method JObject. Parse() is a JObject class method. This parse method is used to parse a JSON string into a C# object. It parses the data of string based on its key value.
Use the JsonProperty
attribute to indicate the name in the JSON. e.g.
[JsonProperty(PropertyName = "binding type")]
public string BindingType { get; set; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With