-1

My question is similar to LINK I have a file that contains tons of JSON objects. I would like to parse the objects from my textfile into a list in my program.

Below is an example of the JSON object contained in the file:

{
     "cars":toyota,
   {
      "type":"sedan",
      "year": 2010
    }
      "color": "Black"
 }

{

      "cars":Ford,
      "type":"sedan",
      "color": "Black"
   }

{

      "cars":Honda,
      "type":"sedan",
      "color": "Black"
    }

These json objects are not seperated with commas and span multiple lines making it hard to parse all of them. Some of these objects also contain multiple object embedded in them. I attempted to use GSON to parse the file but it doesn't seem to be working.

enwafor
  • 101
  • 1
  • 8
  • `"... but it doesn't seem to be working."` -- tells us nothing with which to help you. Please show your code, and tell the details of your problem. – Hovercraft Full Of Eels Jun 10 '16 at 00:10
  • I posted a pretty generic working example using gson 2.8.0 here: http://stackoverflow.com/questions/25346512/read-multiple-objects-json-with-java – wh81752 Feb 14 '17 at 10:41

1 Answers1

-1

You could split the input as a string on '}' and parse the string array individually. This works with simple Json objects.

  • are you aware of the fact that the input contains nested closing parenthesis ( '}' ) ?? To split the input on the 'proper' parenthesis you would need a JSON parser beforehand, right? – wh81752 Feb 14 '17 at 10:45