Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to convert Json format

Shulou Source: shulou.com Published: 2022-06-01 18:33:39 10月03日 Update

This article mainly shows you "how to convert Json format", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "how to convert Json format" this article.

Sometimes it needs to be converted to object, string,map, and so on.

We introduce the dependency of com.alibaba.fastjson.JSONObject

Start the conversion of the format below:

The json data are as follows

{

"providerId": 1

"apiJson": {

"type": {}

"code": "GJWL170415007"

"name": "a"

}

}

Json → String:

String jsonStr = params.getJSONObject ("apiJson") .toString

String → entity class:

User user=

JSONObject.parseObject (jsonStr.toString (), User.class)

Json → Map:

Map map= (Map) JSONObject.parse (String.valueOf (params))

Map → Json:

Map map = new HashMap ()

Map.put ("a", "aaa")

Map.put ("b", "bbb")

Map.put ("c", "ccc")

String json=JSON.toJSONString (map)

System.out.println (json); / / output {"a": "aaa", "b": "bbb", "c": "ccc"}

Json → Array:

JSONArray array=JSONArray.fromObject (stu)

String strArray=array.toString (); the above is all the content of the article "how to convert Json format". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Format content article learning help entity object data easy to understand more organization knowledge editing industry information information channel channel research output Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia vpn Xiaomi Shulou Tech Info Apple