0

The page contains the JavaScript code:

<script type="text/javascript">
    $(document).ready(function () {
        var myVar = new cinema({json_structure}); 
    });

I got this JavaScript code using Jsoup library:

Document doc = Jsoup.connect("http://example.com").timeout(0).get();    
Element script = doc.select("script").get(6);

How can I parse "json_structure"?

Thanks.

Mark Korzhov
  • 2,109
  • 11
  • 31
  • 63
  • At this point, do you have "json_structure" extracted from the script? – Slihp Nov 20 '13 at 19:49
  • @Slihp No, I have extracted all of the JavaScript code, but I don't know how to extract the "json_structure" from it. – Mark Korzhov Nov 20 '13 at 19:52
  • I'd probably use a JSON regex to extract the data. see http://stackoverflow.com/questions/2583472/regex-to-validate-json – Slihp Nov 20 '13 at 19:55

1 Answers1

0

Here's the simplest way:

Pattern p = Pattern.compile(REGEX); // Regex for the value of the key
Matcher m = p.matcher(script.html()); // you have to use html here and NOT text! Text will drop the 'key' part


while( m.find() )
{
    System.out.println(m.group(1)); // value
}

In your case this will output:

json_structure

:)

Fixie
  • 78
  • 5