Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Json.Net: JsonSerializer-Attribute for custom naming [duplicate]

I use the JsonSerializer from Newtonsoft.

But i want to name the json-objects by myself.

I tried the JsonObject attribute

[JsonObject(Description = "MyName", Title = "orThisname")]

JsonArray also didnt work... Is it possible to name the json-objetcs/arrays by myself?

like image 832
user437899 Avatar asked Jul 28 '11 14:07

user437899


People also ask

What is the use of JsonProperty attribute in C#?

JsonPropertyAttribute indicates that a property should be serialized when member serialization is set to opt-in. It includes non-public properties in serialization and deserialization. It can be used to customize type name, reference, null, and default value handling for the property value.

How do I create a custom converter for JSON serialization?

Steps to follow the basic patternCreate a class that derives from JsonConverter<T> where T is the type to be serialized and deserialized. Override the Read method to deserialize the incoming JSON and convert it to type T . Use the Utf8JsonReader that's passed to the method to read the JSON.

What does Jsonconvert Deserializeobject do?

Deserializes the JSON to the specified . NET type. Deserializes the JSON to the specified . NET type using a collection of JsonConverter.


1 Answers

I think I found the solution:

[JsonProperty(PropertyName = "Myname")] 

will rename it.

like image 62
user437899 Avatar answered Sep 20 '22 17:09

user437899