0

I am new to Beanshell scripts, and i want to call a web service that retruns JSON representing images, i am currently doing the call using the following javaScript:-

<script type="text/javascript">
$(function() {
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",
  {
    tags: "gulmarg",
    tagmode: "any",
    format: "json"
  },
  function(data) {
    $.each(data.items, function(i,item){
      $("<img/>").attr("src", item.media.m).appendTo("#images");
      if ( i == 5 ) return false;
    });
  });
})
</script>
<div id="images"></div>

But i need to convert the above javaScript into BeanShell script? can anyone help my in this issue?

Best Regards

John John
  • 1
  • 72
  • 238
  • 501

1 Answers1

1

You can make the connection as follows:

 import java.io.BufferedInputStream;
 in = new BufferedInputStream(new URL(FLICKER_URL).openStream());
 // ...

It is not recommended to roll your own JSON parser; BeanShell is derived from Java, so you can use any public domain libraries to process the JSON. See this question: https://stackoverflow.com/questions/338586/a-better-java-json-library

Community
  • 1
  • 1
GaryMcM
  • 425
  • 3
  • 9