步骤 读取配置文件转换成字符串,代码如下 string contents = System.IO.File.ReadAllText("config.json"); 注意:该语句会抛出文件不存在异常. 使用Newtonsoft.Json将json字符串转换成类的对象,完整代码如下所示 public class Init { public static InitInfo init = new InitInfo(); public Init(){ try { string contents
public class Main implements Serializable { /** * */ private static final long serialVersionUID = -8513279306224995844L; private static final String MYSQL_USERNAME = "demo"; private static final String MYSQL_PWD = "demo"; private stati