在我的应用程序中,我以 J SON 格式从服务器获取响应。在解析时,它显示响应中未终止的错误。因此无法解析它。
我的 json 编码
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000);
HttpConnectionParams.setSoTimeout(client.getParams(), 10000);
HttpResponse response;
try {
HttpPost post = new HttpPost(getString(R.string.base_url)+ "login?json=");
Time dtNow = new Time();
dtNow.setToNow();
String last_login_ts = dtNow.format("%Y-%m-%d %H:%M:%S");
// Log.v("Login_ts",""+last_login_ts);
json.put("pmailtxt", "" + et_username.getText().toString());
json.put("loginpasstxt", "" + et_password.getText().toString());
json.put("merchant_code", "" + getString(R.string.merchant_code));
json.put("last_login_ts", "" + last_login_ts);
// Log.v("Login", ""+json);
// Toast.makeText(getApplicationContext(), ""+json, 700).show();
post.setHeader("json", json.toString());
StringEntity se = new StringEntity(json.toString());
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json"));
post.setEntity(se);
response = client.execute(post);
// Checking response
if (response != null) {
// get a data
InputStream in = response.getEntity().getContent();
String a = json_res_class.convertStreamToString(in);
Log.v("Response", ""+a);//here am getting response
这是我的响应错误
06-07 16:05:55.132: W/System.err(930): org.json.JSONException: Unterminated array at character 5 of [ {"loginSuccess":0,"message":"Wrong username or password"}]
我该如何解决这个问题,任何人都可以知道请帮我解决这个问题。