中希望将空值替换为空白,其中数据来自JSON格式。将空值替换为空白
下面是响应有一些数据值为空的代码我不想在我的应用程序显示空,所以我能做些什么来将null更改为空白。
String detailsURL = "http://10.0.2.2/xp/details2.php?id="+id+"&gender="+strGender+"&curr_user_id="+current_Id;
StringRequest stringRequest = new StringRequest(Request.Method.GET,detailsURL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("details*************",response.trim());
showJSON(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(BlankActivity.this,error.getMessage().toString(),Toast.LENGTH_LONG).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(BlankActivity.this);
requestQueue.add(stringRequest);
下面是showJSON功能
private void showJSON(String response){
String fname = "";
String lname = "";
String mobile1 = "";
String emailVC = "";
String height = "";
String weight = "";
String complexion = "";
String body = "";
String diet = "";
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY);
JSONObject userData = result.getJSONObject(0);
fname = userData.getString(Config.KEY_FNAME);
lname = userData.getString(Config.KEY_LNAME);
mobile1 = userData.getString(Config.KEY_MOBILE1);
emailVC = userData.getString(Config.KEY_EMAIL);
height = userData.getString(Config.KEY_HEIGHT);
weight = userData.getString(Config.KEY_WEIGHT);
complexion = userData.getString(Config.KEY_COMPLEXION);
body = userData.getString(Config.KEY_BODY);
diet = userData.getString(Config.KEY_DIET);
后showJSON方法 – Raghavendra
我已经发布showJSON方法请检查 –
它是连击所有字符串值中的“”(空白),如果如果Array [](空数组),----- ------ so batter to change at service side –