0

I would like to write a method to parse the following records from a file. It is possible for me read each line, start the record at "{" and end it at "}" and process each line in between. However, I was wondering if there was a more elegant way of processing records.

{\n "name": "Jeff Hamilton",\n "address": "101 Main St.",\n "id":"701"\n },\n {\n "name": "Peet Rizzo",\n "address": "109 Main St.",\n "id": "1003"\n }\n

1 Answers1

0

You can split this string into an array.

String newArray[]= str.split("\n },\n {\n");

You can also use a regex here.

Alternatively, a better approach would be to use JSON parsers. I usually use GSON for serialization/deserialization but you can use any.

Taha Tariq
  • 218
  • 1
  • 11