我有一個類似於下面的JSON文檔,我試圖在Groovy中解析它。基本上每個學校(學校信息),我想抓住SCHOOL_COUNTRY
和其他領域。我正在嘗試下面的代碼,但它沒有返回我所需要的。對於列出的每個學校(1000的),我想抓住只有特定的部分,例如:Groovy - JsonSlurper解析JSON文件
def parseJSON(long id) {
JSONFile fileInstance = JSONFile.get(id)
def json = new JsonSlurper().setType(RELAX).parse(new FileReader(fileInstance.filePath))
def schoolInfo = json.SCHOOL_INFO
def schoolName = json.SCHOOL_INFO.SCHOOL_NAME
schoolInfo.each {
render(schoolInfo.SCHOOL_NAME)
}
}
所以基本上每個學校,只是打印出學校的名字。該JSON結構:
[{
"SCHOOL_INFO": {
"SCHOOL_COUNTRY": "Finland",
"SCHOOL NAME": "Findland Higher Learning"
},
"LOCATION": {
"LONGITUDE": "24.999",
"LATITUDE": "61.001"
}
}]