-2

I am parsing a response from imgur. The below is the response that is stored as a single link.

{"data":{"id":"uzgZm0q","title":null,"description":null,"datetime":1468223393,"type":"image\/png","animated":false,"width":267,"height":189,"size":95089,"views":0,"bandwidth":0,"vote":null,"favorite":false,"nsfw":null,"section":null,"account_url":null,"account_id":0,"in_gallery":false,"deletehash":"IJbIGyD5tZFnxrJ","name":"","link":"http:\/\/i.imgur.com\/uzgZm0q.png"},"success":true,"status":200}

How can I take out the id or the link in the response?

I do not want to convert the string to JSON and then get the response. I would like to keep the response as a String itself.

starry
  • 1
  • 8

1 Answers1

-1

You can either convert it into POJO. Or You can use REGEX.

You can use a regex like /"\bid\b":"/ or /"\blink\b":"/ which is of the form /"\b[KEY]\b":"/ to get the index of your desired value and then extract the rest of the string as substring to again use this regex \.+?(?=")\ for your desired result.

Example:

when you use /"\bid\b":"/ on {"id":"abcdefgh","anything":something"}, you get the index of "id":". Use this index to extract the rest of the substring which will be abcdefgh","anything":something"}.

Now using \.+?(?=")\ will give you abcdefgh