package funcLaunDesktop.jsonDataStructure;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
/**
* 构造json串 - 显示文件内容 - send Request json data
* { "tp": "client", #transport protocol
* "data": { "action": "view", "path": "/public_html/README.md" #绝对路径
* "startpage": "0", "linage": "30", } }
* Created by Janesong on 2016/8/29.
*/
public class SendCatFileJson {
private static final
Gson GSON = new GsonBuilder().setPrettyPrinting().create();
private final String tp;
private final JsonData data;
public SendCatFileJson(String tp, JsonData data) {
this.tp = tp;
this.data = data;
}
public String toJson() {
return GSON.toJson(this, SendCatFileJson.class);
}
public String getTP() {
return tp;
}
public JsonData getJsonData() {
return data;
}
public static class JsonData {
private final String action;
private final String path;
private final int startPage;
private final int linage;
public JsonData(String action, String path, int startPage, int linage) {
this.action = action;
this.path = path;
this.startPage = startPage;
this.linage = linage;
}
public String getAction() {
return action;
}
public String getPath() {
return path;
}
}
public static void main(String[] args) {
SendCatFileJson catFileJson = new SendCatFileJson("client", new JsonData("view", "/public_html/README.md", 0, 30));
System.out.println(catFileJson .toJson());
}
}