I am trying to read data from file.lua.
file.lua contains:
Settings = {
{
["msg"] = "в ич об нид мдд/рдд",
["aut"] = "Lightmur",
["cha"] = "5. Поиск спутников",
}, -- [1]
{
["msg"] = "цлк25н ппал шп маг ршам рдру сова (осколки анрол) 5 слотов",
["aut"] = "Savagemode",
["cha"] = "5. Поиск спутников",
}, -- [2]
{
["msg"] = "В СА25 танк/хил/дд/рдд",
["aut"] = "Dralo",
["cha"] = "5. Поиск спутников",
}, -- [3]
{
["msg"] = "в ич об нид мдд/рдд",
["aut"] = "Lightmur",
["cha"] = "5. Поиск спутников",
}, -- [4]
{
["msg"] = "продам |cffa335ee|Hitem:36919:0:0:0:0:0:0:0:80|h[Багровый рубин]|h|rх6 по 120г",
["aut"] = "Аматин",
["cha"] = "2. Торговля: Город",
}, -- [5]
}
How I'am able to read this file with java code?
Where Settings is full log of messages. msg - message, aut - message author, cha - message channel
This is what I'm trying to use: my pom.xml
, java code, and run result
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
JSONParser jsonParser = new JSONParser();
try (FileReader reader = new FileReader(filePath))
{
//Read JSON file
Object obj = jsonParser.parse(reader);
JSONArray employeeList = (JSONArray) obj;
System.out.println(employeeList);
//Iterate over employee array
//employeeList.forEach( emp -> parseEmployeeObject( (JSONObject) emp ) );
}
//Run result:
Unexpected character (S) at position 2.
at org.json.simple.parser.Yylex.yylex(Yylex.java:610)
at org.json.simple.parser.JSONParser.nextToken(JSONParser.java:269)
at org.json.simple.parser.JSONParser.parse(JSONParser.java:118)
at org.json.simple.parser.JSONParser.parse(JSONParser.java:92)
at Main.main(Main.java:21)
I want to get any advice what should I use. Because after I read this file I want to check what is in variable msg by just calling getMsg()
method;
I cant read this in one string but how I can work with data?
File myObj = new File(filePath);
Scanner myReader = new Scanner(myObj);
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
System.out.println(data);
}
myReader.close();
//result
Settings = {
{
["msg"] = "в ич об нид мдд/рдд",
["aut"] = "Lightmur",
["cha"] = "5. Поиск спутников",
}, -- [1]
{
["msg"] = "цлк25н ппал шп маг ршам рдру сова (осколки анрол) 5 слотов",
["aut"] = "Savagemode",
["cha"] = "5. Поиск спутников",
}, -- [2]
{
["msg"] = "В СА25 танк/хил/дд/рдд",
["aut"] = "Dralo",
["cha"] = "5. Поиск спутников",
}, -- [3]
{
["msg"] = "в ич об нид мдд/рдд",
["aut"] = "Lightmur",
["cha"] = "5. Поиск спутников",
}, -- [4]
{
["msg"] = "продам |cffa335ee|Hitem:36919:0:0:0:0:0:0:0:80|h[Багровый рубин]|h|rх6 по 120г",
["aut"] = "Аматин",
["cha"] = "2. Торговля: Город",
}, -- [5]
}
Process finished with exit code 0