Guest User

Untitled

a guest
Oct 29th, 2013
113
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. static final String GuardianUrl = "http://content.guardianapis.com/search?format=json&show-fields=headline%2Cbody%2Cthumbnail%2CtrailText%2ClastModified&date-id=date%2Ftoday&api-key=mykey";
  2.  
  3. 09-21 15:00:18.853: E/JSON Parser(22101): Error converting string to json <html><head> <script language='javascript' type='text/javascript'>function init(_frm) { if (_frm.sent.value == 0) { _frm.sent.value=1; _frm.submit(); } }</script></head><body onload=init(auth)><form name=auth action='http://192.168.3.1:10080/ui/dynamic/guest-login.html' METHOD=GET><input type=hidden name='mac_addr' value='e0:75:7d:d3:15:0a'><input type=hidden name='url' value='http://content.guardianapis.com/search?format=json&#38show-fields=headline%2Cbody%2Cthumbnail%2CtrailText%2ClastModified&#38date-id=date%2Ftoday&#38api-key=pdva9u6ac2rqsx9a7hexzrv3'><input type=hidden name='ip_addr' value='192.168.3.142'><input type=hidden id=sent value='0'><noscript><input type=submit value='continue'></noscript></form></body></html> ... etc
  4.  
  5. public String getJSONFromUrl(String _url) throws IOException {
  6.  
  7. URL url = new URL(_url);
  8. HttpURLConnection connection = (HttpURLConnection)url.openConnection();
  9.  
  10. // Making HTTP request
  11. try {
  12. //ByteArrayOutputStream out = new ByteArrayOutputStream();
  13. //InputStream in = connection.getInputStream();
  14.  
  15. if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
  16. return null;
  17. }
  18.  
  19. String line;
  20. StringBuilder builder = new StringBuilder();
  21.  
  22. BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  23.  
  24. while((line = reader.readLine()) != null) {
  25. builder.append(line);
  26. }
  27.  
  28.  
  29. if (builder.toString().length()>0)
  30. json = builder.toString();
  31. return json;
  32.  
  33. } finally {
  34. connection.disconnect();
  35. }
  36. }
RAW Paste Data