David Petric
David Petric

Reputation: 394

Unable to determine the format type of API Response

I'm trying to parse a array almost like a JSON type like response from an API.

Notice that I can't change or modify the structure of this response.

Maybe someone has an idea of what type is this. I mention that I've searched on google and failed to find a concrete answer to my question.

Here is the response that comes as a string type:

[
  {
    name=David,
    age=7
  },
  {
    name=John,
    age=7
  },
  ..
  ..
  ..
]

Thanks

Upvotes: 2

Views: 123

Answers (2)

Jesse
Jesse

Reputation: 975

You could do some replacements in the result to turn it in to valid JSON then use Json.net to parse, but that may prove to be just as complicated as writing your own parser depending on the possible data that you could get back. If this is the standard response then you could add a quote at the beginning of each line, add a quote before the commas, and then replace the = with ":". After doing that it it would be legal JSON. If the data varies too much though I think I'd recommend a custom parser where you could program for all variations, as my proposed solution isn't very flexible.

Upvotes: 2

Maurice Perry
Maurice Perry

Reputation: 9650

It looks a little like JSON, but it is not valid JSON. I guess you'll have two approaches to deal with this:

  1. Create your own custom parser.
  2. transform your input file to JSON and then use your favorite JSON parser.

I think I would use the former.

Upvotes: 2

Related Questions