java读取json文件

// 读取json
String filepat = "/static/mobile/config.json";
String filepath = request.getRealPath(filepat);
InputStreamReader read = new InputStreamReader(new FileInputStream(filepath), "UTF-8");
BufferedReader br = new BufferedReader(read);
String s = "";
//String ws = "";
String tmpstr = "";
while ((s = br.readLine()) != null) {
tmpstr += s;
}
System.out.println(tmpstr);
JSONObject dataJson = JSONObject.fromObject(tmpstr);
// 找到desktop的第i个数据

//************begin************
JSONArray desktop = dataJson.getJSONArray("apps");
JSONObject is = desktop.getJSONObject(1);
JSONArray st = is.getJSONArray("items");

int ret=0;
for (int i = 0; i < st.size(); i++) {
JSONObject er = st.getJSONObject(i);
String title = er.getString("name");
if (title.equals("领导文件")) {
ret = i;
}
}
st.remove(ret);
//************end************

br.close();
JSONObject jsonResultObject = JSONObject.fromObject(dataJson);
Map retMap = jsonResultObject;

return retMap;

你可能感兴趣的:(java读取json文件)