Java中org.simple.json和org.json库之间的区别?
该org.json.simple库使我们能够阅读和Java编写JSON数据。换句话说,我们可以编码 和解码 JSON对象。该org.json.simple包中包含重要的类象 JSONValue,的JSONObject,JSONArray,JsonString和JsonNumber。我们需要安装 json-simple.jar 文件来执行JSON程序,而org.json库具有用于解析JavaJSON的类。它还在JSON 和XML,HTTP标头,Cookie 和CDF之间转换。该org.json包中包含重要的类象 JSONObject,JSONTokener,JSONWriter,JSONArray,CDL,Cookie和CookieList。我们需要安装json.jar文件以执行JSON程序。
org.simple.json包示例
import org.json.simple.JSONObject;
public class SimpleJsonTest {
public static void main(String[] args) {
JSONObject jsonObj = new JSONObject();
jsonObj.put("empName", "Raja");
jsonObj.put("employeeId", "115");
jsonObj.put("age","30");
System.out.println(jsonObj.toJSONString());
}
}输出结果
{"empName":"Raja","employeeId":"115","age":"30"}org.json包示例
import org.json.*;
public class JSONTest {
public static void main(String args[]) throws JSONException {
String json = "{" + "Name : Jai," + "Age : 25, " + "Salary: 25000.00 " + "}";
JSONObject jsonObj = new JSONObject(json);
System.out.println(jsonObj.toString());
}
}输出结果
{"Salary":25000,"Age":25,"Name":"Jai"}热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语