In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 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!
Brief introduction
The emergence of json is mainly used to describe objects in strings. Compared with serialization of objects, json allows objects to be passed between multiple systems and languages.
In terms of specific form, JSON data is just a string, but it is separated by separators with different meanings. Let's look at the symbols above, where there are symbols such as [], {} and so on.
The parentheses in 1 [] represent an array
2 {} curly braces represent an object
3 double quotation marks "" indicates the attribute value
4 colon: represents the relationship between the front and back. The colon is preceded by the name of the attribute, followed by the value of the attribute, which can be either a basic data type or a reference data type.
Json syntax
JSON data is written as name / value pairs. The name / value consists of the field name, followed by a colon and a value:
{"name": "Bill Gates"}
The key must be a string, surrounded by double quotes, and in JSON, the value must be one of the following data types:
String
Figures
Object (JSON object)
Array
Boolean
Null
The use of fastjson
Maven dependence
Com.alibaba fastjson 1.2.76
Object definition:
@ Data@AllArgsConstructor@NoArgsConstructor@ToString@EqualsAndHashCodepublic class Person {private String name; private int age; private String [] friends;} build objects from json strings public static Person parsePersonFromJson (String personInJson) {Person person = JSON.parseObject (personInJson, Person.class); return person;} convert objects to json strings public static String personToJson (Person person) {String personInJson = JSON.toJSONString (person); return personInJson;} use of Gson
Maven dependence
Com.google.code.gson gson 2.8.6
Build objects from json strings public static Person parsePersonFromJson (String personInJson) {Gson gson = new Gson (); Person person = gson.fromJson (personInJson, Person.class); return person;} convert objects to json strings public static String personToJson (Person person) {Gson gson = new Gson (); String personInJson = gson.toJson (person); return personInJson } this is the end of "how to use fastjson". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.