在我的代码中,我创建了一个 JSONArray 对象。并将两个 JSONObjects 添加到 JSONArray 对象。我正在使用 json-simple-1.1.jar。我的代码是
package jsonjava;
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
public class JsonJava {
public static void main(String[] args)
{
JSONArray ja=new JSONArray();
JSONObject jo=new JSONObject();
jo.put("name","prem");
jo.put("id", 2012103575);
jo.put("Age",20);
ja.add(jo);
JSONObject jo1=new JSONObject();
jo1.put("name","prem");
jo1.put("id", 2012103575);
jo1.put("Age",21);
ja.add(jo1);
for(int i=0;i<ja.size();i++)
System.out.println(ja.get(i));
}
我的问题是如何从 JSONArray 对象(“ja”)中获取第二个对象(“jo1”)的年龄值。我尝试了 ja.get(1).get("Age")。它不起作用。可以一个建议的想法。在此先感谢。