这是从 mysql获取数据后的json结构 蒙戈
"_id" : ObjectId("595a1884ce238efb4d916231"),
"" : [
"\"DDO_CODE:8\"",
"\"DEPT_CODE:3\"",
"\"DDO_NAME:null\"",
"\"DDO_DESIGNATION:PRINCIPAL-IN-CHARGE, REGIONAL INSTITUTE OF PHARMACEUTICAL SCIENCE \\u0026 TECHNOLOGY (RIPSAT),\"",
"\"SELF_DRAW_TAG:O\"",
"\"DDO_ADDRESS:AGARTALA\"",
"\"CREATE_DATE:2002-11-30\"",
"\"CREATE_USER:SUPER\"",
"\"MODIFY_DATE:207-01-19\"",
"\"MODIFY_USER:SEEMA\"",
"\"SOURCE_CODE:11\"",
"\"DISTRICT_CODE:TW\"",
"\"SL_NO:8\"",
"\"PIN:1\""
]
}
**
但我希望mongo遵循以下风格。
**
{
"_id" : ObjectId("57ecd15b00296cadeb2de83c"),
"DDO_CODE" : "3446",
"DEPT_CODE" : "30",
"DDO_NAME" : "DIVISIONAL FOREST OFFICER,",
"DDO_DESIGNATION" : "DIVISIONAL FOREST OFFICER, TELIAMURA DIVISION",
"SELF_DRAW_TAG" : "O",
"DDO_ADDRESS" : "TELIAMURA, WEST TRIPURA",
"CREATE_DATE" : "19-JUN-02",
"CREATE_USER" : "MASTER",
"MODIFY_DATE" : "19-JUN-02",
"MODIFY_USER" : "MASTER",
"SOURCE_CODE" : "404",
"DISTRICT_CODE" : "TRW",
"SL_NO" : "0",
"PIN" : "2775"
}
在我的json数据中,它只创建了2个字段(i字段是id,其他部分 是第二次提交),但第二部分为每个提交了各种文件 线。
my code is...
while (rsMembers.next()) {
String toPrint = "";
int count = 0;
Gson gson = new Gson();
for (int i = 1; i < rsMembers.getMetaData().getColumnCount() + 1; i++) {
toPrint += gson.toJson(rsMembers.getMetaData()
.getColumnName(i) + ":" + rsMembers.getObject(i)) + '\n';
queryResults.append(String.valueOf(" "
+ rsMembers.getMetaData().getColumnName(i) + ":"
+ rsMembers.getObject(i)));
count = rsMembers.getInt(1);
}
//System.out.println("DDDD " + toPrint);
System.out.println("Number of row:"+count);
String[] output = toPrint.split("\n");
System.out.println("PPP"+Arrays.toString(output));
Map<String,Object> dataMap = new HashMap<String,Object>();
//dataMap.put("", Arrays.toString(output));
dataMap.put("", output);
col.insert(new BasicDBObject(dataMap));