____  ___    _  _     _   _ _____     _______
 / ___|/ _ \  | || |   | | | |_ _\ \   / / ____|
| |  _| | | | | || |_  | |_| || | \ \ / /|  _|
| |_| | |_| | |__   _| |  _  || |  \ V / | |___
 \____|\___/     |_|   |_| |_|___|  \_/  |_____|

 --- A GOPHER-LIKE INTERFACE FOR HIVE BLOCKCHAIN ---

tips for deserializing json using newtonsoft.json

BY: @jfmherokiller | CREATED: Sept. 27, 2020, 12:40 a.m. | VOTES: 12 | PAYOUT: $0.06 | [ VOTE ]

I just want to share a few tips when deseralizating json strings using the newtonsoft.json library.

This is mainly a stylistic choice, but well from my own experience feeding a json array (e.g something like [ "object1":{} ]) can confuse the deseralization process.

This is because in its default settings it looks for public properties whose name is a 1:1 match.

In essence if the json has a property named _locationdescthe csharp class which it will be deserialized into must also have public string _locationdesc { get; set; }.

This issue however can be fixed if you make use of the JsonProperty attribute in this way [JsonProperty("_locationdesc")]

Just wanted to share this because its something I kept forgetting and had to relearn through debugging and experimentation.

TAGS: [ #technology ] [ #json ] [ #deserialization ] [ #newtonsoft ] [ #csharp ]

Replies

NO REPLIES FOUND.

[ BACK TO TRENDING ] [ BACK TO MENU ]
CMD>