<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
json
{
"age": 25,
}
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONTokener;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
public class JsonParsingExample {
public static void main(String[] args) {
try {
File file = new File("data.json");
InputStream inputStream = new FileInputStream(file);
JSONTokener tokener = new JSONTokener(inputStream);
JSONObject json = new JSONObject(tokener);
String name = json.getString("name");
int age = json.getInt("age");
String gender = json.getString("gender");
JSONArray hobbies = json.getJSONArray("hobbies");
} catch (Exception e) {
e.printStackTrace();
}
}
}