按照Json格式读取Mongodb中数据
来源:互联网 发布:威廉马歇尔 知乎 编辑:程序博客网 时间:2024/05/23 13:02
Mongodb中的数据如何读
其实我主要是不清楚嵌套方式的读取
DBObject temp = cur.next();读取出来的命令首先是DBObject格式
通过命令:
JSONObject tweettemp = new JSONObject(JSON.serialize(temp));转换为JSON格式。
如果这个Json中还有Json格式:
JSONObject tweet = tweettemp.getJSONObject("tweet");通过这个命令来读取Json中的Json数据
之后
String time = (String)str.get("time");String fullname = (String)str.get("fullname");String tweet2 = (String)str.get("tweet");
可以通过下面的命令读取每个json中的变量。
总的程序:
public void CheckTwitter() throws Exception {BasicDBObject c3 = new BasicDBObject();BasicDBObject c1 = new BasicDBObject();c1.put("name","MittRomney");c3.put("time", "1");//BasicDBObject c3 = new BasicDBObject("time",1);DBCursor cur = collection.find(c1); File ftweet = new File("E:/Matlab/bin/tweet.txt");Writer out23 = new FileWriter(ftweet);while(cur.hasNext()) { DBObject temp = cur.next(); JSONObject tweettemp = new JSONObject(JSON.serialize(temp)); //tweettemp. JSONObject tweet = tweettemp.getJSONObject("tweet"); //System.out.println(tweet); int n = tweet.length(); for (int i=1;i<n+1;i++){ String tempnumber = String.valueOf(i); JSONObject str = tweet.getJSONObject(tempnumber); String time = (String)str.get("time"); String fullname = (String)str.get("fullname"); String tweet2 = (String)str.get("tweet"); this.countretweet(fullname); this.countdaytweet(time); this.countyuetweet(time);//this.writetweet(tweet2); out23.write(tweet2); out23.write("\r\n"); //System.out.println(time); //System.out.println(fullname); //System.out.println(tweet2); } //System.out.println(countname); for (int j=0;j<24;j++){ //System.out.println(countdaytweet[j]); } for (int j=0;j<62;j++){ //System.out.println(countyuetweet[j]); } out23.close(); //String json = temp.toString(); } }
- 按照Json格式读取Mongodb中数据
- 在Android中操作JSON数据-读取JSON格式数据/创建JSON格式数据
- Sliverlight 读取 JSON 格式数据
- Android读取JSON格式数据
- 读取、创建Json格式数据
- 结构体内部偏移的妙用 从文件中按照固定格式读取数据
- mongodb mongoexprt 导出数据 json csv格式
- js和java按照json格式导出数据
- .NET 读取 JSON格式的数据
- android读取服务器json格式数据
- JQGRID读取json数据的格式要求
- ASP.NET 读取Json格式数据
- hive存储读取json格式的数据
- 创建并读取JSON格式数据
- ajax读取json格式数据或者说获取浏览器XHR中数据
- 怎么从mongodb中按照日期导出用户数据
- C#中读取json数据。
- VB2005中按照16进制读取串口缓冲区数据
- C常用函数t的实现
- Stylecop vs FXcop 区别
- 同步与异步
- 堆排序
- Bash script学习的一写memo
- 按照Json格式读取Mongodb中数据
- Android触摸屏输入系统
- 自定义分页控件
- hibernate4与hibernate3的区别
- try-finally语句
- [Leetcode] Partition List **
- Oracle 11g 新特性 -- Transparent Data Encryption (透明数据加密TDE) 增强 说明
- 23种设计模式之工厂方法模式
- 反编译问题