-1

I have a website that is in plain text. The website is in a format like this:

{"code1":"Text I want copied","code2":"Second text I want to copy"}

Every time the website refreshes though, the texts I want copied change in length. I am curious how I could retrieve the text starting after ' :" ' and before ' ", ', using Java. I want the same thing to happen with the second text as well. I also would like to remove the html tags. Help will be greatly appreciated.

Kaxon
  • 25
  • 3
  • that text you mention is in JSON format. Please see this post http://stackoverflow.com/questions/2591098/how-to-parse-json-in-java – Tah Dec 21 '15 at 04:01
  • Still don't understand how I can parse it from the website. – Kaxon Dec 21 '15 at 04:33

1 Answers1

0

Using the org.json library, you could parse the JSON like:

String myJSONString = "{\"code1\":\"Text I want copied\",\"code2\":\"Second text I want to copy\"}";
JSONObject object = new JSONObject(myJSONString);
String[] keys = JSONObject.getNames(object);

String firstText = (String) object.get(keys[0]);
String secondText = (String) object.get(keys[1]);

For parsing the web page, you can use the JSoup library. See an example from this answer.

Community
  • 1
  • 1
badjr
  • 2,166
  • 3
  • 20
  • 31