
本文共 1260 字,大约阅读时间需要 4 分钟。
第一种方法:
依赖:
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
JSONParser parser = new JSONParser();
JSONObject jsonObject = null;
try {
jsonObject = (JSONObject)parser.parse(new FileReader("D:/电信数据/1524574800.json"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JSONArray jsonDatas = (JSONArray) jsonObject.get("data");
Gson gson = new Gson();
ArrayList<WIFIGateway> wifiGateways = new ArrayList<WIFIGateway>();
for (Object object : jsonDatas)
{
JSONObject jsonData = (JSONObject) object;
WIFIGateway wifi = gson.fromJson(jsonData.toString(), WIFIGateway.class);
wifiGateways.add(wifi);
}
第二种方法:
<dependency>
<groupId>com.mchange</groupId>
<artifactId>mchange-commons-java</artifactId>
<version>0.2.7</version>
</dependency>
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mchange.io.FileUtils;
String path="/getTableData.txt";//需要解析的文件的路径
JSONObject json = JSON.parseObject(FileUtils.getContentsAsString(new File(path)));
发表评论
最新留言
关于作者
