Advertisement
Guest User

Untitled

a guest
Feb 7th, 2014
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import com.google.gson.Gson;
  2.  
  3. import java.net.URL;
  4. import java.net.URLConnection;
  5. import java.util.Scanner;
  6.  
  7. public class RadioContent
  8. {
  9. private String url;
  10. private String stringContent;
  11. private RadioContent gsonContent;
  12. private String find;
  13.  
  14. public Object getValue( String find )
  15. {
  16. return gsonContent.find;
  17. }
  18.  
  19. public void setURL( String url )
  20. {
  21. this.url = url;
  22. }
  23.  
  24. public void loadContent()
  25. {
  26. URLConnection connection = null;
  27. try
  28. {
  29. connection = new URL( url ).openConnection();
  30. Scanner scanner = new Scanner( connection.getInputStream() );
  31. scanner.useDelimiter( "\\Z" );
  32. stringContent = scanner.next();
  33. }
  34. catch( Exception ex )
  35. {
  36. ex.printStackTrace();
  37. }
  38. }
  39.  
  40. public void convertToJson()
  41. {
  42. Gson gson = new Gson();
  43. gsonContent = gson.fromJson( stringContent, RadioContent.class );
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement