import java.util.ArrayList;
import java.util.List;
import com.alibaba.fastjson.JSON;
public class ALiJson {
public static void main(String[] args) {
Ali ali1 = new ALiJson().new Ali();
ali1.setKey("aliKK1");
ali1.setValue("aliVV1");
Ali ali2 = new ALiJson().new Ali();
ali2.setKey("aliKK2");
ali2.setValue("aliVV2");
Ali ali3 = new ALiJson().new Ali();
ali3.setKey("aliKK3");
ali3.setValue("aliVV3");
List<Ali> list = new ArrayList<Ali>();
list.add(ali1);
list.add(ali2);
String jsonString = JSON.toJSONString(list);
System.out.println(jsonString);
}
public class Ali{
private String key;
private String value;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
}
import java.util.List;
import com.alibaba.fastjson.JSON;
public class ALiJson {
public static void main(String[] args) {
Ali ali1 = new ALiJson().new Ali();
ali1.setKey("aliKK1");
ali1.setValue("aliVV1");
Ali ali2 = new ALiJson().new Ali();
ali2.setKey("aliKK2");
ali2.setValue("aliVV2");
Ali ali3 = new ALiJson().new Ali();
ali3.setKey("aliKK3");
ali3.setValue("aliVV3");
List<Ali> list = new ArrayList<Ali>();
list.add(ali1);
list.add(ali2);
list.add(ali3);
System.out.println(list);
JSONObject jsonObject = new JSONObject();
for(Ali ali : list) {
jsonObject.put(ali.getKey(), ali.getValue());
}
String jsonString2 = jsonObject.toJSONString();
System.out.println(jsonString2);
String jsonString = JSON.toJSONString(list);
System.out.println(jsonString);
}
public class Ali{
private String key;
private String value;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
}