有我的 JSON 结构:
{
"date":"19.11.2013",
"parent":{
"child1":[
{
"date":"2013-11-19",
"time":"10:30",
},
{
"date":"2013-11-19",
"time":"12:20",
}
],
"child2":[
{
"date":"2013-11-19",
"time":"10:30",
},
{
"date":"2013-11-19",
"time":"12:20",
}
]
}
}
这是我目前的代码:
public class json {
public static void main(String[] args) throws IOException, ParseException {
URL urlData = new URL("http://path.to/json");
BufferedReader reader = new BufferedReader(new InputStreamReader(
urlData.openConnection().getInputStream(), "utf-8"));
String struct = reader.readLine();
JSONParser parser = new JSONParser();
Object obj = parser.parse(struct);
JSONObject lev1 = (JSONObject) obj;
System.out.println(lev1.get("date"));
}
}
我得到了一个日期值(19.11.2013),但我不知道如何获取孩子的日期和时间值。我正在使用 json-simple 库。