This article is a mirror article of machine translation, please click here to jump to the original article.

View: 2819|Reply: 1

[Source] Newtonsoft.Json deserializes string strings to remove spaces

[Copy link]
Posted on 2/8/2024 10:47:21 AM | | | |
Requirements: Calling a third-party interface using http returns a JSON string, which needs to be deserialized into an object and then saved to the database. During the testing process, we found that many attribute contents in the json string returned by the other party had spaces, and we needed to remove the spaces from the valued attributes before saving them to the database, otherwise, we would have problems.

Since there are many object properties, if each attribute is usedTrim()The method of removing spaces is more troublesome. So, possibly passCustom JSON converterto fulfill our needs.

First, the default deserialized output value is as shown in the following figure:



Now, after adding a custom JSON converter, the spaces before and after the deserialized string are removed, as shown in the image below:



The code is as follows:

Reference:The hyperlink login is visible.





Previous:Oracle queries return field full caps issues
Next:MySQL current time plus day and timestamp
 Landlord| Posted on 7/29/2025 11:06:44 AM |
.NET/C# despaces the string non-empty string in the object (class instance).
https://www.itsvse.com/thread-11044-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com