SolrDocumentList docs = response.getResults();
1、JSONObject返回类似{"SolrDocument":{“1”:{},“2”:{}}
Map<Integer,Object> mapDoc = new HashMap<Iteger, Object>();
int count = 1;
for(SolrDocument doc : docs){
mapDoc.put(count, doc);
count++;
}
JSONObject json = new JSONObject();
json.put("SolrDocument", mapDoc);
//json.put(mapDoc);输出{ {“1”:{},“2”:{}}
String strResult = json.toString();
2、JSONArray返回格式:[{},{}]为json数组
JSONArray arrJson = new JSONArray();
for(SolrDocument doc :docs){
arrJson.add(doc);
}
String strResult = arrJson.toString();
3、JSONObject和JSONArray组合显示{"data":[{},{},{}]}
在2的基础上继续向下写:
JSONObject json = new JSONObject();
json.put(