私はファイルからJSONを持っています。ファイルからJSON配列を解析するには?
{
"from_excel":[
{
"solution":"Fisrt",
"num":"1"
},
{
"solution":"Second",
"num":"2"
},
{
"solution":"third",
"num":"3"
},
{
"solution":"fourth",
"num":"4"
},
{
"solution":"fifth",
"num":"5"
}
]
}
解決と番号のリストを解析します。 org.json.simple libに使用さ
。*
はこの1
Object obj = parser.parse(new FileReader("E:\\json.txt")); JSONObject jsonObject = (JSONObject) obj; out.println(jsonObject.get("from_excel")); JSONObject obj_new = (JSONObject) jsonObject.get("from_excel"); JSONArray solution = (JSONArray) obj_new.get("solution"); Iterator iterator = solution.iterator(); while (iterator.hasNext()) { out.println(iterator.next()); }
は私が間違って何をやってみては?
JSONArray array = obj.getJSONArray("from_excel");
解決策はlib" org.json.simple。* "私は互換性のない型でエラーを試します。 –
@Neerajはこれを 'org.json.simple'で動作させます –