我目前编写了一个链接到我的 android 应用程序的 php 脚本,但是我有一个问题:我的 php 脚本有 2 个输出:
- [“成功”]
- 无效的
当输出为空时,我想在我的 android 应用程序中:
if (json.equals(null)) {
goodrating.setVisibility(View.GONE);
badrating.setVisibility(View.GONE);
如果输出为 ["Success"] 我希望我的 android 应用程序执行以下操作:
} else {
goodrating.setVisibility(View.VISIBLE);
badrating.setVisibility(View.VISIBLE);
}
问题尚未解决
通过异步任务更新我的完整代码:
protected String doInBackground(String... params) {
if (fb.isSessionValid()) {
String resulta;
JSONObject obj = null;
String jsonUser = fb.request("me");
obj = Util.parseJson(jsonUser);
String email = obj.optString("email");
String phonename = prefs.getString("esmlphone", "value");
InputStream isr = null;
HttpClient httpclient = new DefaultHttpClient();
String tablename = prefs.getString("hazahuwakeylurl",
"walashi");
HttpPost httpost = new HttpPost(
"secret");
HttpResponse resposne = httpclient.execute(httpost);
HttpEntity entity = resposne.getEntity();
isr = entity.getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(isr, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
isr.close();
resulta = sb.toString();
final JSONArray jArray = new JSONArray(resulta);
try {
for (int i = 0; i < jArray.length(); i++) {
JSONObject json = jArray.getJSONObject(0);
if (json.isNull("response")) {
goodrating.setVisibility(View.GONE);
badrating.setVisibility(View.GONE);
} else {
goodrating.setVisibility(View.VISIBLE);
badrating.setVisibility(View.VISIBLE);
}
}
} catch (Exception e) {
Log.d("visibility", e.toString());
}
}
return null;
}