我是FlexJson的新手,我正试图对其有所了解。我从一段简单的代码开始。这是代码:
public class Statements {
private String parent;
private ArrayList<String> children = new ArrayList<String>();
public Statements(String parent)
{
this.parent =parent;
}
public void setPrent(String parent)
{
this.parent = parent;
}
public String getPrent()
{
return parent;
}
public void setChildren(ArrayList<String> children)
{
this.children = children;
}
public ArrayList<String> getChildren()
{
return children;
}
public static void main(String[] args)
{
String parent = "A";
ArrayList<String> children = new ArrayList<String>();
children.add("a1");
children.add("a2");
children.add("a3");
Statements s = new Statements(parent);
s.setChildren(children);
JSONSerializer serializer = new JSONSerializer().prettyPrint(true);
System.out.println(serializer.exclude("*.class").include("children").serialize( s ));
}
}
这是输出:
{
"children": [
"a1",
"a2",
"a3"
],
"parent": "A"
}
我想要得到的是以下输出:
{
"parent": "A",
"children": [
"a1",
"a2",
"a3"
]
}
实际输出按字母顺序排序。我正在尝试获得的是上面显示的输出。任何人都可以帮助这样做。非常感谢您的协助。