package cn.tongdun.robot.web; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.parser.Feature; import java.util.List; /** * @author hello * @date 2019-10-18 13:46 * @description */ public class Hello { public static void main(String[] args) { String str = "[ " + " { " + " "type": "SEND", " + " "dataMapping": { " + " "userid": "account", " + " "ts": "ts", " + " "sign": "sign", " + " "mobile": "taskItem.mobile", " + " "msgcontent": "taskItem.content", " + " "time": "taskItem.scheduleTime", " + " "URL": "http://1.1.1.1:8081/api/sms/send", " + " "password": "password" " + " }, " + " "maxSendCount": "1000", " + " "tps": "50", " + " "channelPattern": "JSON", " + " "sendSeparate": "", " + " "httpHeaderParams": { " + " "Authorization": "authorization" " + " } " + " }, " + " { " + " "type": "REPORT", " + " "dataMapping": { " + " "userid": "account", " + " "ts": "ts", " + " "sign": "sign", " + " "password": "password", " + " "URL": "http://1.1.1.1/api/v2/sms/query" " + " }, " + " "tps": "10", " + " "channelPattern": "JSON" " + " } " + "]"; // Object list = JSON.parse(str, Feature.OrderedField); List<HelloBean> list = JSON.parseObject(str, new TypeReference<List<HelloBean>>() {}.getType(), Feature.OrderedField); System.out.println(list); } }
package cn.tongdun.robot.web; import com.alibaba.fastjson.JSONObject; /** * @author hello * @date 2019-10-18 14:29 * @description */ public class HelloBean { /** * type : REPORT * dataMapping : {"userid":"account","ts":"ts","sign":"sign","password":"password","URL":"http://47.99.224.177:8081/api/v2/sms/query"} * tps : 10 * channelPattern : JSON */ private String type; private JSONObject dataMapping; private String tps; private String channelPattern; public String getType() { return type; } public void setType(String type) { this.type = type; } public JSONObject getDataMapping() { return dataMapping; } public void setDataMapping(JSONObject dataMapping) { this.dataMapping = dataMapping; } public String getTps() { return tps; } public void setTps(String tps) { this.tps = tps; } public String getChannelPattern() { return channelPattern; } public void setChannelPattern(String channelPattern) { this.channelPattern = channelPattern; } }