how to iterate through json objects in java

前端 未结 3 1881
离开以前
离开以前 2021-01-07 00:35

I am trying to iterate through my json file and get required details here is my json

{
\"000\": {
    \"component\": \"c\",
    \"determinantType\": \"dt\",         


        
3条回答
  •  执念已碎
    2021-01-07 01:01

    try this...

    FileReader file = new FileReader("test.json");
    Object obj = parser.parse(file);
    System.out.println(obj);
    JSONObject jsonObject = (JSONObject) obj;            
    
    Iterator iterator = jsonObject .iterator();  
    
    for(Iterator iterator = jsonObject.keySet().iterator(); iterator.hasNext();) {
        String key = (String) iterator.next();
        System.out.println(jsonObject.get(key));
    }
    

提交回复
热议问题