Org Json 简明教程

Org.Json - Environment Setup

本章带你完成在基于 Windows 和 Linux 的系统上设置 Org.Json 的过程。遵循一些简单的步骤,无需任何复杂的设置过程,即可轻松安装 Org.Json 并将其与当前 Java 环境集成。安装时需要用户管理。

This chapter takes you through the process of setting up Org.Json on Windows and Linux based systems. Org.Json can be easily installed and integrated with your current Java environment following a few simple steps without any complex setup procedures. User administration is required while installation.

System Requirements

JDK

Java SE 2 JDK 1.5 or above

Memory

1 GB RAM (recommended)

Disk Space

No minimum requirement

Operating System Version

Windows XP or above, Linux

让我们继续进行安装 Org.Json 的步骤。

Let us now proceed with the steps to install Org.Json.

Step 1: Verify your Java Installation

首先,你的系统中需要安装 Java 软件开发工具包 (SDK)。要验证这一点,请根据所使用的平台执行以下两个命令。

First of all, you need to have Java Software Development Kit (SDK) installed on your system. To verify this, execute any of the two commands depending on the platform you are working on.

如果 Java 安装已正确完成,则它将显示 Java 安装的当前版本和规范。以下表中给出了一个示例输出。

If the Java installation has been done properly, then it will display the current version and specification of your Java installation. A sample output is given in the following table.

Platform

Command

Sample Output

Windows

Open command console and type − >java –version

java version "11.0.11" 2021-04-20 LTS Java™ SE Runtime Environment 18.9 (build 11.0.11+9-LTS-194) Java HotSpot™ 64-Bit Server VM 18.9 (build 11.0.11+9-LTS-194, mixed mode)

Linux

Open command terminal and type − $java –version

java version "11.0.11" 2021-04-20 LTS Open JDK Runtime Environment 18.9 (build 11.0.11+9-LTS-194) Open JDK 64-Bit Server VM (build 11.0.11+9-LTS-194, mixed mode)

  1. We assume the readers of this tutorial have Java SDK version 11.0.11 installed on their system.

  2. In case you do not have Java SDK, download its current version from www.oracle.com/technetwork/java/javase/downloads/index.html and have it installed.

Step 2: Set your Java Environment

设置环境变量 JAVA_HOME 以指向计算机上安装 Java 的基本目录位置。例如,

Set the environment variable JAVA_HOME to point to the base directory location where Java is installed on your machine. For example,

Sr.No.

Platform & Description

1

Windows Set JAVA_HOME to C:\ProgramFiles\java\jdk11.0.11

2

Linux Export JAVA_HOME = /usr/local/java-current

将 Java 编译器位置的完整路径附加到系统路径。

Append the full path of Java compiler location to the System Path.

Sr.No.

Platform & Description

1

Windows Append the String "C:\Program Files\Java\jdk11.0.11\bin" to the end of the system variable PATH.

2

Linux Export PATH = $PATH:$JAVA_HOME/bin/

如上所述,从命令提示符执行命令 java -version

Execute the command java -version from the command prompt as explained above.

Step 3: Install Org.Json Library

org.json @ MVNRepository 下载最新版本的 org.json jar 文件。在编写本教程时,我们已下载 json-20211205,并将其复制到 C:\>JSON 文件夹中。

Download the latest version of org.json jar file from org.json @ MVNRepository. At the time of writing this tutorial, we have downloaded json-20211205, and copied it into C:\>JSON folder.

OS

Archive name

Windows

json-20180813.jar

Linux

json-20180813.jar

Mac

json-20180813.jar

Step 4: Set JSON_JAVA Environment

设置 JSON_JAVA 环境变量以指向 org.json jar 存储在你机器上的基本目录位置。我们假设我们已将 json-20211205.jar 存储在 JSON 文件夹中。

Set the JSON_JAVA environment variable to point to the base directory location where org.json jar is stored on your machine. Let’s assuming we’ve stored json-20211205.jar in the JSON folder.

Sr.No

OS & Description

1

Windows Set the environment variable JSON_JAVA to C:\JSON

2

Linux export JSON_JAVA = /usr/local/JSON

3

Mac export JSON_JAVA = /Library/JSON

Step 5: Set CLASSPATH Variable

CLASSPATH 环境变量设置为指向 JSON.simple jar 所在位置。

Set the CLASSPATH environment variable to point to the JSON.simple jar location.

Sr.No

OS & Description

1

Windows Set the environment variable CLASSPATH to %CLASSPATH%;%JSON_JAVA%\json-20211205.jar;.;

2

Linux export CLASSPATH = $CLASSPATH:$JSON_JAVA/json-20211205.jar:.

3

Mac export CLASSPATH = $CLASSPATH:$JSON_JAVA/json-20211205.jar:.