English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Everyone usually uses Java objects to convert JSON strings. Null or empty string properties do not need to be generated into the JSON string.
The following method generates JSON string properties, even if some properties are not used.
JSONArray jsonarray = JSONArray.fromObject(ecmMessageMap.values()); msgObj = jsonarray.toString(); {"actionType":"","clientIp":"","ecServiceNumber":"","ecmMessageEventFlow":null,"endTime":"","eventId":"","faultEventFlowList":[],"groupId":"","psize":0,"receiver":"","receiverEcServiceNumber":"","sender":"","startTime":"","successEventIds":[]}
Gson Usage:
Gson g = new Gson(); msgObj = g.toJson(ecmMessage); 1
If large data transmission or storage in the database, it is reasonable to generate JSON strings, which will save a lot of storage space and transmission speed. For example, exchange monitoring mq data in JSON format, exchange monitoring disaster recovery database storage.
This article on how to generate JSON without null or empty string properties (detailed explanation) is all the content that the editor shares with everyone. It is hoped that it can provide a reference for everyone and everyone is expected to support the Shouting Tutorial more.