java中的json解析
来源:互联网 发布:c语言 登录系统 编辑:程序博客网 时间:2024/06/04 08:41
@Override
public void getDoctor(){
List<Doctor> list=new ArrayList<Doctor>();
String json = loadJson("http://www.pkuih.edu.cn/page/emp!readList.html?empid=");
List<DoctorSub> list1=new ArrayList<DoctorSub>();
try {
JSONArray jsonArray = new JSONArray(json);
for(int i=0;i<jsonArray.length();i++){
Doctor doctor=new Doctor();
DoctorSub docSub=new DoctorSub();
JSONObject object = jsonArray.getJSONObject(i);
doctor.setName(object.getString("nameZh"));
//doctor.setTitle(array.get);
if(object.getJSONObject("sex")!=null){
if("男性".equals(object.getJSONObject("sex").getString("name"))){
doctor.setGender("1");
}else if("女性".equals(object.getJSONObject("sex").getString("name"))){
doctor.setGender("2");
}
}
//doctor.setGender(object.getString("sex"));
doctor.setPicture(object.getString("photoImg"));
doctor.setCode(object.getString("id"));
//doctor.setNameAcronym(object.getString("nameEn"));
doctor.setOrgCode("112628");
docSub.setOrgCode("112628");
if(object.getJSONObject("duty")!=null)
{doctor.setTitle(object.getJSONObject("duty").getString("name"));}
docSub.setDoctorCode(doctor.getCode());
doctor.setClinicName(object.getJSONObject("department").getString("nameEn"));
doctor.setClinicCode(object.getJSONObject("department").getString("departmentId"));
docSub.setMajorCode(object.getJSONObject("department").getString("departmentId"));
doctor.setServiceState(object.getString("workState"));
doctor.setRegistrationdate(DateFormater.parseSimpleDate(object.getString("created"), "yyyy-MM-dd"));
doctor.setPracticecatogary(object.getString("professionType"));
list.add(doctor);
list1.add(docSub);
}
doctorDao.batchInsert(list, null);
docotorSubDao.batchInsert(list1, null);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String loadJson(String url) {
StringBuilder json=new StringBuilder();
try {
URL urlObject = new URL(url);
URLConnection uc = urlObject.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream(),"UTF-8"));
String inputLine=null;
while((inputLine=in.readLine())!=null){
json.append(inputLine);
}
in.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
log.error("解析json的url异常");
} catch (IOException e) {
// TODO Auto-generated catch block
log.error("读取流异常");
}
return json.toString();
}
}
public void getDoctor(){
List<Doctor> list=new ArrayList<Doctor>();
String json = loadJson("http://www.pkuih.edu.cn/page/emp!readList.html?empid=");
List<DoctorSub> list1=new ArrayList<DoctorSub>();
try {
JSONArray jsonArray = new JSONArray(json);
for(int i=0;i<jsonArray.length();i++){
Doctor doctor=new Doctor();
DoctorSub docSub=new DoctorSub();
JSONObject object = jsonArray.getJSONObject(i);
doctor.setName(object.getString("nameZh"));
//doctor.setTitle(array.get);
if(object.getJSONObject("sex")!=null){
if("男性".equals(object.getJSONObject("sex").getString("name"))){
doctor.setGender("1");
}else if("女性".equals(object.getJSONObject("sex").getString("name"))){
doctor.setGender("2");
}
}
//doctor.setGender(object.getString("sex"));
doctor.setPicture(object.getString("photoImg"));
doctor.setCode(object.getString("id"));
//doctor.setNameAcronym(object.getString("nameEn"));
doctor.setOrgCode("112628");
docSub.setOrgCode("112628");
if(object.getJSONObject("duty")!=null)
{doctor.setTitle(object.getJSONObject("duty").getString("name"));}
docSub.setDoctorCode(doctor.getCode());
doctor.setClinicName(object.getJSONObject("department").getString("nameEn"));
doctor.setClinicCode(object.getJSONObject("department").getString("departmentId"));
docSub.setMajorCode(object.getJSONObject("department").getString("departmentId"));
doctor.setServiceState(object.getString("workState"));
doctor.setRegistrationdate(DateFormater.parseSimpleDate(object.getString("created"), "yyyy-MM-dd"));
doctor.setPracticecatogary(object.getString("professionType"));
list.add(doctor);
list1.add(docSub);
}
doctorDao.batchInsert(list, null);
docotorSubDao.batchInsert(list1, null);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String loadJson(String url) {
StringBuilder json=new StringBuilder();
try {
URL urlObject = new URL(url);
URLConnection uc = urlObject.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream(),"UTF-8"));
String inputLine=null;
while((inputLine=in.readLine())!=null){
json.append(inputLine);
}
in.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
log.error("解析json的url异常");
} catch (IOException e) {
// TODO Auto-generated catch block
log.error("读取流异常");
}
return json.toString();
}
}
0 0
- Java中的Json解析
- Java中的JSON解析
- java中的JSon解析
- Java中的JSon解析
- JAVA中的 JSON 解析
- java中的json解析
- simple-json在java中的解析
- java中的json概念及解析
- iOS中的JSON解析
- android中的Json解析
- C#中的Json解析
- python中的json解析
- Javascript中的JSON解析
- iOS中的JSON解析
- android中的json解析
- Android中的JSON解析
- Python 中的json解析
- JAVA中的JSON解析和生成AND GSON开源库
- 某些3D游戏优化小技巧汇总
- 数据库同步,配置两个数据源(mysql)
- C# 使用微软的Visual Studio International Pack 类库提取汉字拼音首字母
- Java学习笔记之数据类型
- HP集群配置过程-详细实例
- java中的json解析
- Mysql单字段容量过大insert导致segfault问题。
- Newtonsoft.Json高级用法
- 数据库事务以及锁机制(乐观锁、悲观锁)
- 【遇见大咖】测试界:你的圈子在哪?
- 沃美影城等加盟天津鲁能城共襄盛会
- 卡马克
- bootstrap结合angularjs各式按钮(3)
- Clear:both问题