Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the case problem of the first letter of JSON.toJSONString ()

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to solve the case problem of the first letter of JSON.toJSONString ()". The editor shows you the operation process through an actual case. The method of operation is simple and fast, and it is practical. I hope this article "how to solve the problem of capitalization of the first letter of JSON.toJSONString ()" can help you solve the problem.

JSON.toJSONString initial case problem scenario

Recently, I was working on a hospital project. The input and output parameters of the his part of the hospital were encapsulated by mirth, and a version of the interface document was written to me.

I was a little upset when I read it. The initials were all capitalized. It is about the same as the annoying degree that the class names in my last project are all capitalized.

Because I need to use http request to call his interface, I can only use String to pass parameters, so I need to use the JSON tool to convert to String.

But the problem was exposed, JSON.toJSONString, which converts the first letter of the field name to lowercase, which does not correspond to my need for uppercase.

How to solve

You need to use the @ JSONField annotation on the uppercase field, and the usage example will be pasted below. Just use this annotation to assign the required field name to the name attribute in the @ JSONField annotation.

JSONObject.toJSONString changed the case of attributes to class A {undefined / / xxx private String QKRQ; / / xxxx private String QKDH;}

I wanted to serialize the An object through fastjson and pass it to the client, but the data passed to the client is not what I want. The attributes such as QKRQ and QKDH are serialized through JSONObject.toJSONString to become qKRQ and qKDH.

The first letter of the property returned to the client after the @ JSONField (name= "QKRQ") setting will not be lowercase!

This is the end of the introduction on "how to solve the case problem of the first letter of JSON.toJSONString ()". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report