我正在研究这个项目,我得到了Json的响应并将它们转换为商店类型的对象。要求是制作项目的jar文件并将其插入到另一个将从这些对象中创建文件的项目中。到现在为止还挺好。问题从这里开始:
public static void main(String[] args) throws IOException, Exception {
/* Propertiess practise = new Propertiess();
practise.InitializeConfigParameters();
practise.Print();*/
ArrayList<Shop> ArrayofShops = new ArrayList<>
(YelpJsonApi.SearchForShops("Burgers", "San Francisco"));
}
当我从第一个项目运行main时,eveything运行完美,但是当我从第二个项目中运行相同的main时出现此错误:
Exception in thread "main" Unexpected token END OF FILE at position 8192.
at org.json.simple.parser.JSONParser.parse(Unknown Source)
at org.json.simple.parser.JSONParser.parse(Unknown Source)
at Basics.YelpJsonApi.SearchForShops(YelpJsonApi.java:53)
at Storage.Demo.main(Demo.java:21)
Java结果:1
此错误指向此部分:
public class YelpJsonApi {
private static final String USER_AGENT = "Mozilla/5.0";
private static final File shops = new File("C:\\Users\\Stathis\\Documents\\shops.txt");
public static ArrayList<Shop> SearchForShops(String CityName, String Category) throws IOException, Exception{
String url = "someLink" + Category + "&location=" + CityName;
Document doc = Jsoup.connect(url)
.userAgent(USER_AGENT)
.header("Authorization", "someText")
.ignoreContentType(true)
.get();
String responseText = doc.text();
//System.out.println("TEXT:" + responseText);
System.out.println("**************************************************");
JSONParser parser = new JSONParser();
File shops = new File("shops.txt");
ArrayList<Shop> shopListFromApi = new ArrayList<>();
try {
// Object obj = parser.parse(new FileReader(shops));
FileWriter fw = new FileWriter(shops);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(responseText);
JSONObject jsonObject = (JSONObject) parser.parse(new FileReader(shops));
StringReader rT = new StringReader(responseText); // διαφορετικά η από κάτω γραμμή θα πετάει error String cannot be converted to reader
jsonObject = (JSONObject) parser.parse(rT);
...
}
尽管我已经阅读了stackoverflow(和其他网站)上的大多数文章,并且尝试了大多数选项,但错误似乎并没有消失。我怀疑我的文件可能有问题(即使我已经尝试将我的信息存储到其他文件),因为EOF异常位于8192位而不是开始。 提前谢谢!