Searchs s = new Searchs();
String JsonContext = new Util().ReadFile("C:\\Users\\rucong\\Desktop\\db.txt");
JSONArray jsonArray = JSONArray.fromObject(JsonContext);
int size = jsonArray.size();
System.out.println("Size: " + size);
String dataId=null;
String name= null;
String keyWords=null;
Object bean = null;
String beans = null;
String jjfa=null;
String rqbh=null;
String zzms=null;
String mc=null;
String gjz=null;
String tjr=null;
String lx=null;
int size2;
HashMap<String, String> map = new HashMap<String, String>();
for(int i = 0; i < size; i++){
JSONObject jsonObject = jsonArray.getJSONObject(i);
bean = jsonObject.get("bean");
dataId= (String) jsonObject.get("dataId");
name= (String) jsonObject.get("name");
JSONArray json = JSONArray.fromObject(bean);
size2 = json.size();
for(int n=0; n<size2; n++){
JSONObject js = json.getJSONObject(n);
jjfa = (String) js.get("解决方案");
rqbh =(String) js.get("日期编号");
zzms =(String) js.get("症状描述");
mc=(String) js.get("名称");
gjz =(String) js.get("关键字");
tjr =(String) js.get("提交人");
lx =(String) js.get("类型");
beans="{\"解决方案\":\""+jjfa+"\",\"日期编号\":\""+rqbh+"\",\"症状描述\":\""+zzms+"\",\"名称\":\""+mc+"\",\"关键字\":\""+gjz+"\",\"提交人\":\""+tjr+"\",\"类型\":\""+lx+"\"}";
}
dataId= (String) jsonObject.get("dataId");
name= (String) jsonObject.get("name");
try {
keyWords = java.net.URLDecoder.decode(jsonObject.get("keyWords").toString(), "UTF-8").trim();
} catch (Exception e) {
e.printStackTrace();
}
map.put("name", name);
map.put("keyWords", keyWords);
map.put("dataId", dataId);
map.put("thumb", "0");
map.put("userIds", "userIds");
s.addIndex(map,beans);
}
}
public static void main(String[] args) throws UnsupportedEncodingException {
Searchs s = new Searchs();
String JsonContext = new Util().ReadFile("C:\\Users\\rucong\\Desktop\\db.txt");
JSONArray jsonArray = JSONArray.fromObject(JsonContext);
int size = jsonArray.size();
System.out.println("Size: " + size);
String dataId=null;
String name= null;
String keyWords=null;
Object bean = null;
String beans = null;
HashMap<String, String> map = new HashMap<String, String>();
for(int i = 0; i < size; i++){
JSONObject jsonObject = jsonArray.getJSONObject(i);
bean = jsonObject.get("bean");
dataId= (String) jsonObject.get("dataId");
name= (String) jsonObject.get("name");
keyWords=(String) jsonObject.get("keyWords");
try {
beans = bean.toString();
} catch (Exception e) {
e.printStackTrace();
}
map.put("name", name);
map.put("keyWords", keyWords);
map.put("dataId", dataId);
map.put("thumb", "0");
map.put("userIds", "userIds");
s.addIndex(map,beans);
}
}
//读取json文件
package com.beijia.solr.util;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class Util {
public String ReadFile(String Path){
BufferedReader reader = null;
String laststr = "";
try{
FileInputStream fileInputStream = new FileInputStream(Path);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "gbk");
reader = new BufferedReader(inputStreamReader);
String tempString = null;
while((tempString = reader.readLine()) != null){
laststr += tempString;
}
reader.close();
}catch(IOException e){
e.printStackTrace();
}finally{
if(reader != null){
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return laststr;
}
}