JSON数据写入和解析

如何写入JSON

需要第三方jar包,JSON包

//写入json数据

public static String sendJson() {
JSONObject json = new JSONObject();
User user = new User("username", "address", "password", 18);
json.put("user", user);
return json.get("user").toString();
}

 

//得到json数据

public static void main(String[] args) {
JSONObject jsonObject = JSONObject.fromObject(sendJson());
String username = jsonObject.getString("username");
System.out.println(username);
}

 

posted @ 2016-05-21 20:12  飞尽堂前燕  阅读(392)  评论(0编辑  收藏  举报