在我的项目中,正在处理json
以接收并向服务器发送响应。它适用于English
个字母。
现在的问题是,当使用非英文字母(泰卢固语,泰米尔语或印地语)时,会自动将其转换为服务器端数据库中的垃圾值(??????????
)。
调用服务器的示例方法:
AsyncHttpClient mNewCaller = new AsyncHttpClient();
mNewCaller.setTimeout(DEFAULT_TIMEOUT);
final ProgressDialog mpd = new ProgressDialog(mContext);
mpd.setTitle("Please wait");
mpd.setMessage("Signing in");
mpd.setCancelable(false);
RequestParams mParams = new RequestParams();
mParams.add(Constants.JSON_HEADER, obj1.toString());
mParams.add(Constants.JSON_BODY, obj2.toString());
// Pref.setValue(getApplicationContext(), Constants.PREF_IMEIID, uid);
Log.e("login", mParams.toString());
LayoutInflater layoutInflater = LayoutInflater.from(mContext);
View promptView = layoutInflater.inflate(R.layout.device_name, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);
alertDialogBuilder.setView(promptView);
final EditText code = (EditText) promptView.findViewById(R.id.deviceName);
alertDialogBuilder.setCancelable(false).setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
authCode = code.getText().toString();
sendDName(authCode, mContext);
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertD = alertDialogBuilder.create();
Constants.EMAIL_ID = email;
String url = DynamicURL;
mNewCaller.get(Login.DynamicURL, mParams, new JsonHttpResponseHandler() {
@Override
public void onStart() {
super.onStart();
if (mpd != null) {
mpd.show();
}
}
@Override
public void onSuccess(int statusCode, Header[] headers, String responseString) {
super.onSuccess(statusCode, headers, responseString);
Log.e("frag", responseString + " " + statusCode);
if (mpd != null) {
mpd.dismiss();
}
if (responseString.equalsIgnoreCase("NODEVICENAME")) {
alertD.show();
}
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
super.onSuccess(statusCode, headers, response);
Constants.EMAIL_ID = email;
Log.e("frag", response.toString() + " " + statusCode);
JSONArray jAry = null;
if (mpd != null) {
mpd.dismiss();
}
if (response.has(Constants.STATUS)) {
try {
if (response.getString(Constants.STATUS).equalsIgnoreCase("TABLOGINFAILED")) {
Snack.show(mContext, "Wrong email or password");
// Toast.makeText(getApplicationContext(), "Wrong email or password", Toast.LENGTH_LONG).show();
return;
}
} catch (JSONException e) {
e.printStackTrace();
}
try {
if (response.getString(Constants.STATUS).equalsIgnoreCase("NODEVICENAME")) {
alertD.show();
return;
}
} catch (JSONException e) {
e.printStackTrace();
}
}
try {
Constants.DEVICE_NAME = response.getString(Constants.DEVICENAME);
Constants.CUSTOMER_ID = response.getString("customerid");
jAry = response.getJSONArray(Constants.CAMPAIGN_LIST);
if (response.has("otpenabled")) {
Constants.OTP_ENABLED = response.getBoolean("otpenabled");
Constants.OTP_ENABLED = false;
}
Constants.PREF_JSONARRAY = jAry.toString();
} catch (JSONException e) {
e.printStackTrace();
}
Constants.login = 1;
intent = new Intent(Login.this, Home.class);
startActivity(intent);
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
super.onSuccess(statusCode, headers, response);
Log.e("frag", response.toString() + " " + statusCode);
if (mpd != null) {
mpd.dismiss();
}
Log.e("frag", response.toString());
}
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
super.onFailure(statusCode, headers, responseString, throwable);
Log.e("frag", responseString + " " + statusCode);
if (statusCode == 500) {
// Snack.show(mContext, "Please try again with a valid email id");
new SweetAlertDialog(Login.this, SweetAlertDialog.ERROR_TYPE)
.setTitleText("User does not exist")
.setContentText("Please try again with a valid email id")
.show();
}
if (mpd != null) {
mpd.dismiss();
}
/*if (responseString.equalsIgnoreCase("FALSE")) {
alertD.show();
}*/
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
super.onFailure(statusCode, headers, throwable, errorResponse);
Log.e("frag", statusCode + " failed obj");
try {
if (statusCode == 0) {
new SweetAlertDialog(Login.this, SweetAlertDialog.ERROR_TYPE)
.setTitleText("Server Down")
.setContentText("Please try again later")
.show();
} else if (errorResponse.getString(Constants.STATUS).equalsIgnoreCase("NODEVICENAME")) {
alertD.show();
return;
} else if (errorResponse.getString(Constants.STATUS).equalsIgnoreCase("TABLOGINFAILED")) {
// Snack.show(mContext, "Please check your email or password");
new SweetAlertDialog(Login.this, SweetAlertDialog.ERROR_TYPE)
.setTitleText("Incorrect login details")
.setContentText("Please check your email or password")
.show();
} else {
}
} catch (JSONException e) {
e.printStackTrace();
}
// Snack.show(mContext, "Wrong email or password");
if (mpd != null) {
mpd.dismiss();
}
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONArray
errorResponse) {
super.onFailure(statusCode, headers, throwable, errorResponse);
Log.e("frag", errorResponse.toString() + " " + statusCode);
Snack.show(mContext, "Wrong email or password");
if (mpd != null) {
mpd.dismiss();
}
}
});