新手求解 java 如何从一串字符串中提取关键字,并存入mysql

我从txt文档中读取了大概几万行的字符串,并存入string数组中,每个数组里的内容大概如下
{"gps":{"type":"gps","Lon":116.34948495921601,"status":"available","Lat":39.9621098626166},"time":"2015-11-11 19:24:57+0800","wifi":[{"ssid":"TP-LINK_514","mac":"88:25:93:69:36:d5","dbm":-43},{"ssid":"LiebaoFree150","mac":"5e:4b:d6:d5:b1:31","dbm":-56},{"ssid":"TP-LINK_5G_514","mac":"88:25:93:69:36:d4","dbm":-51},{"ssid":"10-331","mac":"1c:7e:e5:55:22:b6","dbm":-82},{"ssid":"1%ts","mac":"fc:d7:33:7f:51:d8","dbm":-77},{"ssid":"BUPT-dot1x","mac":"d8:c7:c8:02:a1:19","dbm":-85},{"ssid":"516NB","mac":"fc:d7:33:7f:e9:dc","dbm":-70},{"ssid":"Kevin","mac":"f4:b7:e2:b7:0e:25","dbm":-86},{"ssid":"ChinaNet","mac":"2e:4b:d6:ab:5e:2b","dbm":-62},{"ssid":"517","mac":"fc:d7:33:7f:50:30","dbm":-79},{"ssid":"OP","mac":"36:de:1a:71:82:0c","dbm":-78},{"ssid":"BUPT-1","mac":"d8:c7:c8:02:a1:18","dbm":-89},{"ssid":"360WiFi-414","mac":"8c:a9:82:00:8d:03","dbm":-71},{"ssid":"TP-LINK 414","mac":"80:89:17:fd:8e:82","dbm":-82},{"ssid":"TP-LINK_L","mac":"fc:d7:33:80:08:ea","dbm":-90},{"ssid":"211_Class8_SICE_Building5","mac":"ec:88:8f:43:33:d4","dbm":-91},{"ssid":"TP-LINK_1303","mac":"fc:d7:33:80:09:6c","dbm":-87}],"cell":[{"connected":true,"mnc":"46001","cell_type":"gsm_uni","dbm":-79,"m":"one","networktype":"UMTS","cid":7089899,"lac":41052}]}

请问我该用什么方法,把其中每个{}内的内容提取出来,并按照ssid,mac,dbm 分别存入mysql中
而且每串字符串中,{}的数目不固定
谢谢

6个回答

你这明显是json格式的字符串,上网看看怎么解析json字符串就好了

sinat_25272999
sinat_25272999 谢谢
4 年多之前 回复
sinat_25272999
sinat_25272999 谢谢
4 年多之前 回复

你这就是json格式,用JSONObject直接转成json对象,自己读取就是了

sinat_25272999
sinat_25272999 谢谢
4 年多之前 回复

构造和这个json对应的bean类,然后转换
最后再调用操作数据库的函数保存
http://www.oschina.net/code/snippet_931591_17607
http://blog.csdn.net/zhaozhenhua88/article/details/5998748

sinat_25272999
sinat_25272999 谢谢
4 年多之前 回复
sinat_25272999
sinat_25272999 谢谢
4 年多之前 回复

首先把这个string转换成json 然后把wifi的取出 然后循环保存就可以了

sinat_25272999
sinat_25272999 谢谢
4 年多之前 回复
sinat_25272999
sinat_25272999 谢谢
4 年多之前 回复

你这是Json格式的字符串,很好解析的,直接查一下Java解析Json字符串一大堆。

你这是json格式的字符串,建议用gson来解析,保存到实体中, 适合新手!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问