#android #html #json
#Android #HTML #json
Вопрос:
я регистрируюсь, используя электронную почту и пароль, если электронная почта и домен завершены, это успешная работа, но если a@a.com например, передать по электронной почте, чем вернуть мне html, и мое приложение вылетает, так как обращаться с этим контентом
public String webregister(String url, String u, String p)
{
// Create a new httpclient and send post header
HttpClient httpClient = new DefaultHttpClient();
// returns true if username and password is valid
HttpPost httpPost = new HttpPost(url);
String json = null;
InputStream is;
try
{
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("username", u));
nameValuePairs.add(new BasicNameValuePair("password", p));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// getting the response
HttpResponse httpResponse = httpClient.execute(httpPost);
is = httpResponse.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line "n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
return json;
}
ErrorLogcat
06-27 19:40:23.585: E/Register Url(1474): ---->http://interntest.monitorwerbung.at/studio/webservices/register
06-27 19:40:23.585: E/Register(1474): ----><!doctype html>
06-27 19:40:23.585: E/Register(1474): <!--[if lt IE 7 ]> <html lang="de" class="no-js ie6"> <![endif]-->
06-27 19:40:23.585: E/Register(1474): <!--[if IE 7 ]> <html lang="de" class="no-js ie7"> <![endif]-->
06-27 19:40:23.585: E/Register(1474): <!--[if IE 8 ]> <html lang="de" class="no-js ie8"> <![endif]-->
06-27 19:40:23.585: E/Register(1474): <!--[if IE 9 ]> <html lang="de" class="no-js ie9"> <![endif]-->
06-27 19:40:23.585: E/Register(1474): <!--[if (gt IE 9)|!(IE)]><!--> <html lang="de" class="no-js"> <!--<![endif]-->
06-27 19:40:23.585: E/Register(1474): <head>
06-27 19:40:23.585: E/Register(1474): <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>monitorwerbung - Errors</title>
06-27 19:40:23.585: E/Register(1474): <link href="/studio/backend.ico" type="image/x-icon" rel="icon" /><link href="/studio/backend.ico" type="image/x-icon" rel="shortcut icon" />
06-27 19:40:23.585: E/Register(1474): <link rel="stylesheet" type="text/css" href="/studio/css/reset.css" /><link rel="stylesheet" type="text/css" href="/studio/css/jquery-ui-1.8.18.custom.css" /><link rel="stylesheet" type="text/css" href="/studio/css/default.css" /><link rel="stylesheet" type="text/css" href="/studio/css/jquery.minicolors.css" /><script type="text/javascript" src="/studio/js/modernizr.js"></script><script type="text/javascript" src="/studio/js/jquery-1.7.1.min.js"></script><script type="text/javascript" src="/studio/js/jquery.minicolors.js"></script><script type="text/javascript" src="/studio/js/jquery-ui-1.8.18.custom.min.js"></script><script type="text/javascript" src="/studio/js/jquery.ui.datepicker-de.js"></script><script type="text/javascript" src="/studio/js/global.js"></script></head>
06-27 19:40:23.585: E/Register(1474): <body>
06-27 19:40:23.585: E/Register(1474): <div id="LiveSearchResult"></div>
06-27 19:40:23.585: E/Register(1474): <div class="wrapper">
06-27 19:40:23.585: E/Register(1474): <div class="sidebar">
06-27 19:40:23.585: E/Register(1474): <div id="logo">
06-27 19:40:23.585: E/Register(1474): <img src="/studio/img/logo.png" alt="Peakmedia" /> </div>
06-27 19:40:23.585: E/Register(1474): <div class="profile-info">
06-27 19:40:23.585: E/Register(1474): Hallo <a href="/studio/managers/profile"></a>! |
06-27 19:40:23.585: E/Register(1474): <a href="/studio/managers/logout">Abmelden</a> <div>27.06.2014 16:10</div>
06-27 19:40:23.585: E/Register(1474): </div>
06-27 19:40:23.585: E/Register(1474): <div id="livesearch">
06-27 19:40:23.585: E/Register(1474): <input type="text" name="data[Search][livesearch]" id="SearchLivesearch" placeholder="Durchsuchen" />
06-27 19:40:23.585: E/Register(1474): </div>
06-27 19:40:23.585: E/Register(1474):
06-27 19:40:23.585: E/Register(1474):
06-27 19:40:23.585: E/Register(1474): <div class="menu">
06-27 19:40:23.585: E/Register(1474): <ul>
06-27 19:40:23.585: E/Register(1474): <li><a href="/studio/home">Dashboard</a></li>
06-27 19:40:23.585: E/Register(1474): </ul>
06-27 19:40:23.585: E/Register(1474): <ul>
06-27 19:40:23.585: E/Register(1474):
06-27 19:40:23.585: E/Register(1474): </ul>
06-27 19:40:23.585: E/Register(1474): <ul>
06-27 19:40:23.585: E/Register(1474): </ul>
06-27 19:40:23.585: E/Register(1474): <ul>
06-27 19:40:23.585: E/Register(1474): </ul>
06-27 19:40:23.585: E/Register(1474): <ul>
06-27 19:40:23.585: E/Register(1474): </ul> </div>
06-27 19:40:23.585: E/Register(1474): </div>
06-27 19:40:23.585: E/Register(1474): <div class="content">
06-27 19:40:23.585: E/Register(1474): <h2>An Internal Error Has Occurred.</h2>
06-27 19:40:23.585: E/Register(1474): <p class="error">
06-27 19:40:23.585: E/Register(1474): <strong>Error: </strong>
06-27 19:40:23.585: E/Register(1474): An Internal Error Has Occurred.</p>
06-27 19:40:23.585: E/Register(1474): </div>
06-27 19:40:23.585: E/Register(1474): <div class="clear"></div>
06-27 19:40:23.585: E/Register(1474): </div>
06-27 19:40:23.585: E/Register(1474): <script type="text/javascript">
06-27 19:40:23.585: E/Register(1474): //<![CDATA[
06-27 19:40:23.585: E/Register(1474): $(document).ready(function () {$("#SearchLivesearch").bind("keyup", function (event) {if ($("#SearchLivesearch").val().length > 2) {$.ajax({async:true, data:$("#SearchLivesearch").serialize(), dataType:"html", success:function (data, textStatus) {$("#LiveSearchResult").html(data);$("#LiveSearchResult").show()}, type:"post", url:"/studio/admin/search/livesearch"});return false;} else {$("#LiveSearchResult").hide();}});});
06-27 19:40:23.585: E/Register(1474): //]]>
06-27 19:40:23.585: E/Register(1474): </script></body>
06-27 19:40:23.585: E/Register(1474): </html>
Ответ №1:
я получил решения своего собственного вопроса, я кое-что попробовал, и это работает для меня
boolean containsHTML=false;
Pattern htmlPattern = Pattern.compile(".*\<[^>] >.*", Pattern.DOTALL);
containsHTML=htmlPattern.matcher(data).matches();
if(containsHTML)
{
\ not parsing or set message : invalid data
}
else
{
\ do jsonparsing here
}