繁体   English   中英

解析Java中JSON文件的字段

[英]Parsing fields of JSON file in Java

我有一个以下格式的 JSON 文件,并且想解析数据以插入表中。 我坚持如何从文件中提取数据。 数据如下所示:

{"business_id": "vcNAWiLM4dR7D2nwwJ7nCA", "full_address": "4840 E Indian School Rd\nSte 101\nPhoenix, AZ 85018", "hours": {"Tuesday": {"close": "17:00", "open": "08:00"}, "Friday": {"close": "17:00", "open": "08:00"}, "Monday": {"close": "17:00", "open": "08:00"}, "Wednesday": {"close": "17:00", "open": "08:00"}, "Thursday": {"close": "17:00", "open": "08:00"}}, "open": true, "categories": ["Doctors", "Health & Medical"], "city": "Phoenix", "review_count": 7, "name": "Eric Goldberg, MD", "neighborhoods": [], "longitude": -111.98375799999999, "state": "AZ", "stars": 3.5, "latitude": 33.499313000000001, "attributes": {"By Appointment Only": true}, "type": "business"}

到目前为止我有这个代码:

fReader = new FileReader(filePath);
bufferedReader = new BufferedReader(fileReader);
String line;
bufferedReader.readLine();
int index = 0;
while ((line = bufferedReader.readLine()) != null) {
     String businessInfo[] = line.split("\t");
                
     //add a new object based on my OOP design

为什么不使用 JSON 解析器,如 Gson 或 Jackson 等? 将有效负载传递给它,它将返回 Object 您将转换为您的类型。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM