示例
import org.json.*;
public class JSONObjectTypeValuesTest {
public static void mAIn(String[] args) throws JSONException {
JSONObject jsonObj = new JSONObject(
"{" +
"Name : Adithya," +
"Age : 22, " +
"Salary: 10000.00, " +
"IsSelfEmployee: false " +
"}"
);
System.out.println(jsonObj.getString("Name")); // returns string
System.out.println(jsonObj.getInt("Age")); // returns int
System.out.println(jsonObj.getDouble("Salary")); // returns double
System.out.println(jsonObj.getBoolean("IsSelfEmployee")); // returns true/false
}
}
输出
Adithya 22 10000.0 false
以上就是如何在Java中从JSON对象中获取不同类型的值。

