public class Json implements Comparable<Json> { // There are value types private int Type_String = 1; private int Type_Array = 2; private int Type_List = 3; // Key always is String private String key; // There are three types of value private int valueType; private String valueString; private List<Json> valueArray;// 本质一致,表现不同 private List<Json> valueList; // indent depth private int depth;
public Json(String key, String value) { this.key = key; this.valueType = Type_String; this.valueString = value; this.depth = 0; } public Json(String key, int type) { this.key = key;
if (type == Type_List) { this.valueType = Type_List; this.valueList = new LinkedList<Json>(); } else if (type == Type_Array) { this.valueType = Type_Array; this.valueArray = new LinkedList<Json>(); } }
public void addJsonToList(Json json) { if (valueList != null) { valueList.add(json);
adjustDepth(); } }
public void addJsonToArray(Json json) { if (valueArray != null) { valueArray.add(json);