In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to use fastjson". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
JSONObject's method
Package name: com.alibaba.fastjson maven dependency:
The use of com.alibaba fastjson 1.2.7JSONObject converts strings to JSONObject objects String str = "{\" desc\ ":\" string in json format\ ",\" sex\ ":\" male\ "}"; JSONObject jo = JSONObject.parseObject (str)
JSONObject can convert extremely complex json objects, as can the following json statement, and obtain the corresponding values through the corresponding methods.
{"protocol": {"itemID": "9527", "companyID": "4399", "userID": "233"}," operateInfo ": {" cooptaskSceneDataPackets ": [{" taskID ":" 123", "runSceneID": "345"," dataTagCode ":" objection " "dataTagID": "", "dataTagName": "Yes", "dataTagBelongOrg": "}, {" taskID ":" 126 "," runSceneID ":" 345 "," dataTagCode ":"," dataTagID ":" "dataTagName": "Yes", "dataTagBelongOrg": ""}, {"taskID": "123"," runSceneID ":" 345", "dataTagCode": "unable", "dataTagID": "15th", "dataTagName": "Yes" "dataTagBelongOrg": "572"}, {"taskID": "124", "runSceneID": "235", "dataTagCode": "", "dataTagID": "", "dataTagName": "" "dataTagBelongOrg": ""}]} convert String objects to entity classes
Use JSONObject.parseObject (String text, Class clazz)
String str = "{\" itemID\ ":\" 9527\ ",\" companyID\ ":\" 4399\ ",\" userID\ ":\" 4399\ "}"; EntityProtocol entityProtocol = JSONObject.parseObject (str, EntityProtocol.class)
If the type does not match, the entity class with all attributes null is created.
Add or modify properties to the JSONObject object
Use the .put (key,value) method
If the key parameter is not in the original object, the key property is added and assigned to value in the original object.
If the key parameter exists, change the value of key to value
/ / JSONObject.put (String key,Object value); jo.put ("key", "value"); jo.put ("sex", "modify"); JSONObject.putAll (Map
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.