在得到entity格式数据时,获取某一项值使用自己定义的get方法,例如:
OwnerInsightChartEntity chartsData=ownerInsightChartService.getDataByTaskIdAndChartCode(taskId, chartCode); String xDatas = chartsData.getXData(); //若xDatas的数据格式为字符串:2,3,4,5,6 String [] xDatasStrArr = xDatas.split(","); //则使用split方法获得到String []类型的字符串数组{"2","3","4","5","6"} Integer length = xDatasStrArr.length; //获取字符串数组长度 String str = xDatasStrArr[0]; //获取字符串数组第一个值 OwnerInsightChartEntity territoryJson = OwnerInsightChartDao.findByTaskIdAndChartCode(taskId, chartCode); String ydata = territoryJson.getYData();//获取字符创,例如:{"province":[120,345,234,56,567],"city":[10,20,30,40,50]} JSONObject yDataObjec = JSONObject.parseObject(ydata);//转换为json对象: {"province":[120,345,234,56,567],"city":[10,20,30,40,50]} JSONArray yDataCityArr = JSONObject.parseArray(yDataObjec.get("city").toString() );//获取JSONArray格式数据: [10,20,30,40,50];获取数组长度使用size()方法 List<String> yDataCityList = new ArrayList<String>(); for(int i = 0; i < yDataCityArr.size(); i++){ yDataCityList.add(yDataCityArr.get(i).toString()); } System.out.println(yDataCityList);//List<String>格式的数据: [10, 20, 30, 40, 50]