如何使用org.json.simple解析不带根元素的JSON文件? [英] How to parse a JSON File without root element using org.json.simple?

查看:147
本文介绍了如何使用org.json.simple解析不带根元素的JSON文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用org.json.simple库解析json文件"c:/employeesRecord.json".下面是示例json数据,每个记录按文件中的下一行分隔.

I want to parse json file "c:/employeesRecord.json" using org.json.simple library. Below is sample json data, each record is sperated by next line in the file.

{"Employees ":["A ;B ;C ;D ;E ;F"],"JobTitle":"Software Engineer"}
{"Employees ":["A ;B ;C ;D ;E ;F"],"JobTitle":"Software Engineer"}
{"Employees ":["A ;B ;C ;D ;E ;F"],"JobTitle":"Software Engineer"}
...

如何使用org.json.simple解析没有根元素的json文件.

How to parse such json file without root element using org.json.simple.

推荐答案

您可以调整"文件中的输入并将其更改为有效的json格式

You can "tweak" the input from the file and change it into a valid json format

String json = <your json from file>
json = "[" + json + "]";
json = json.replace("\n",",");
// parse your json, now it should be a valid.

这篇关于如何使用org.json.simple解析不带根元素的JSON文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆