
本文档主要讲述的是Python之模块学习;python是由一系列的模块组成的,每个模块就是一个py为后缀的文件,同时模块也是一个命名空间,从而避免了变量名称冲突的问题。模块我们就可以理解为lib库,如果需要使用某个模块中的函数或对象,则要导入这个模块才可以使用,除了系统默认的模块(内置函数)不需要导入外。希望本文档会给有需要的朋友带来帮助;感兴趣的朋友可以过来看看
2
The Flexjson is a lightweight library for serializing and deserializing Java objects into and from JSON format. We can also serialize an array of objects using the serialize() method of JSONSerializer class, this performs a shallow serialization of the target instance.
public String serialize(Object target)
In the below program, we need to serialize an array of objects.
import flexjson.JSONSerializer;
public class JsonSerializeArrayTest {
public static void main(String[] args) {
JSONSerializer serializer = new JSONSerializer().prettyPrint(true);
Student stud1 = new Student("Adithya", "Sai", 28, "Hyderabad");
Student stud2 = new Student("Jai", "Dev", 30, "Chennai");
Student stud3 = new Student("Ravi", "Chandra", 35, "Pune");
Student[] students = {stud1, stud2, stud3};
String jsonStr = serializer.serialize(students);
System.out.println(jsonStr);
}
}
// Student class<strong>
</strong>class Student {
private String firstName;
private String lastName;
private int age;
private String address;
public Student() {}
public Student(String firstName, String lastName, int age, String address) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.address = address;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public int getAge() {
return age;
}
public String getAddress() {
return address;
}
public String toString() {
return "Student[ " +
"firstName = " + firstName +
", lastName = " + lastName +
", age = " + age +
", address = " + address +
" ]";
}
}[
{
"address": "Hyderabad",
"age": 28,
"class": "Student",
"firstName": "Adithya",
"lastName": "Sai"
},
{
"address": "Chennai",
"age": 30,
"class": "Student",
"firstName": "Jai",
"lastName": "Dev"
},
{
"address": "Pune",
"age": 35,
"class": "Student",
"firstName": "Ravi",
"lastName": "Chandra"
}
]以上就是我们如何使用Java中的flexjson将对象数组序列化?的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号