I call some data in text file format from an API (https://en120.grepolis.com/data/players.txt). Each line in this text file is a single player with his information (name, ID, etc.). After every player is a line break. My current problem is I have no good strategy how to get each player separated and also call his specific information to push it into a new player object that will be saved in a json array.
Example:
first line in the text file (id, name, alliance_id, points, rank, towns)
6415107,Aragorn2,972,40297,461,4
should become to
{
"id": 6415107,
"name": "Aragorn2",
"alliance_id": 972,
"points": 40297,
"rank": 461
"towns": 4
}
In theory I could detect the first line break, take all characters from 0 to the position of the line break, remove this substring from the text file and process the data. But this feels really dowdy and I can imagine there is any good method with RegEx and match
.
Thanks for your help