【发布时间】:2014-01-03 08:53:32
【问题描述】:
我有想要解析的 JSON 文件。 JSON 文件(“myfile”)的格式如下:
{
"LanguageLevels": {
"1": "Początkujący",
"2": "ŚrednioZaawansowany",
"3": "Zaawansowany",
"4": "Ekspert"
}
}
我想从语言级别检索键 2 的值 (ŚrednioZaawansowany)。
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
public class JsonSimpleExample {
public static void main(String[] args) {
JSONParser parser = new JSONParser();
try {
Object obj = parser.parse(new FileReader("myfile");
JSONObject jsonObject = (JSONObject) obj;
JSONObject jsonChildObject = (JSONObject)jsonObject.get("LanguageLevels");
接下来要做什么?我如何迭代它?
【问题讨论】:
-
我建议阅读官方文档,如果有的话,看看他们的例子。