Spell out a simple JSON,
The effect is probably:
{"Data": List}, there are two elements in the list, also JSON format
The code is:
public static void Main (string[] args) {
Jsonobject all=new jsonobject ();//FINAL JSON
Jsonarray array=new Jsonarray ();//json list
Jsonobject data=new jsonobject ();//json list Element
Hashmap<string,object> list=new hashmap<string,object> ()//batch assignment to data
List.put ("T1", "ttt111");
List.put ("T2", "ttt222");
Data.putall (list);
Array.add (data);
Hashmap<string,object> list2=new hashmap<string,object> ();
List2.put ("T1", "ttt333");
List2.put ("T2", "ttt444");
Data.putall (LIST2);
Array.add (data);
All.put ("Data", array);
try {
String Result=json.json (All);
SYSTEM.OUT.PRINTLN (result);
catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
The result of the output is:
{"Data": [{"T2": "ttt444", "T1": "ttt333"},{"T2": "ttt444", "T1": "ttt333"}]}
Among them, Jsonobject is Com.alibaba.dubbo.common.json.jsonobject,jsonarray is Com.alibaba.dubbo.common.json.JSONArray