EditText: how to remove “null” string obtained from a Json2019 Community Moderator ElectionSafely turning a JSON string into an objectHow do I format a Microsoft JSON date?How can I pretty-print JSON in a shell script?Stop EditText from gaining focus at Activity startup.NET - JSON serialization of enum as stringHow to parse JSON in JavaParsing values from a JSON file?Convert JS object to JSON stringHow can I pretty-print JSON using JavaScript?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?
Why would a flight no longer considered airworthy be redirected like this?
My adviser wants to be the first author
Why one should not leave fingerprints on bulbs and plugs?
How difficult is it to simply disable/disengage the MCAS on Boeing 737 Max 8 & 9 Aircraft?
Do these spellcasting foci from Xanathar's Guide to Everything have to be held in a hand?
Can a druid choose the size of its wild shape beast?
What do Xenomorphs eat in the Alien series?
How to write cleanly even if my character uses expletive language?
Welcoming 2019 Pi day: How to draw the letter π?
How to read the value of this capacitor?
Did Ender ever learn that he killed Stilson and/or Bonzo?
Is a party consisting of only a bard, a cleric, and a warlock functional long-term?
Sailing the cryptic seas
Who is flying the vertibirds?
If I can solve Sudoku can I solve Travelling Salesman Problem(TSP)? If yes, how?
Do I need life insurance if I can cover my own funeral costs?
SOQL: Populate a Literal List in WHERE IN Clause
How can I track script which gives me "command not found" right after the login?
Do I need to be arrogant to get ahead?
Professor being mistaken for a grad student
How to simplify this time periods definition interface?
Should we release the security issues we found in our product as CVE or we can just update those on weekly release notes?
How to change two letters closest to a string and one letter immediately after a string using notepad++
Awsome yet unlucky path traversal
EditText: how to remove “null” string obtained from a Json
2019 Community Moderator ElectionSafely turning a JSON string into an objectHow do I format a Microsoft JSON date?How can I pretty-print JSON in a shell script?Stop EditText from gaining focus at Activity startup.NET - JSON serialization of enum as stringHow to parse JSON in JavaParsing values from a JSON file?Convert JS object to JSON stringHow can I pretty-print JSON using JavaScript?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?
Is there any way I can eliminate the "null" string of an editing text brought from a JSONObject response? and just show the empty EditText.
He did it in the following way.
if (jsonResponse.getString(DataManager.Name).equals("null")
edtName.setText("");
else
edtName.setText(jsonResponse.getString(usersDataInfo.getNombre()));
But when the field comes with information, it enters the instruction again and removes the information.
JSON
"ID": 23,
"NOMBRE": null,
"APELLIDOPATERNO": null,
"APELLIDOMATERNO": null,
"TELEFONO": null,
"CELULAR": null,
"NACIMIENTO": null,
"SEXO": null,
"USUARIOID": 7
android json android-edittext
add a comment |
Is there any way I can eliminate the "null" string of an editing text brought from a JSONObject response? and just show the empty EditText.
He did it in the following way.
if (jsonResponse.getString(DataManager.Name).equals("null")
edtName.setText("");
else
edtName.setText(jsonResponse.getString(usersDataInfo.getNombre()));
But when the field comes with information, it enters the instruction again and removes the information.
JSON
"ID": 23,
"NOMBRE": null,
"APELLIDOPATERNO": null,
"APELLIDOMATERNO": null,
"TELEFONO": null,
"CELULAR": null,
"NACIMIENTO": null,
"SEXO": null,
"USUARIOID": 7
android json android-edittext
Can you post an example of your Json please?
– Skizo-ozᴉʞS
Mar 6 at 18:09
"ID": 23, "NOMBRE": null, "APELLIDOPATERNO": null, "APELLIDOMATERNO": null, "TELEFONO": null, "CELULAR": null, "NACIMIENTO": null, "SEXO": null, "USUARIOID": 7
– Gregorio Tancitaro
Mar 6 at 19:33
I added an answer :)
– Skizo-ozᴉʞS
Mar 6 at 19:48
I would suggest to use Gson or something similar for parsing between json and objects. then you can do a null check on object.
– Arutha
Mar 6 at 20:50
add a comment |
Is there any way I can eliminate the "null" string of an editing text brought from a JSONObject response? and just show the empty EditText.
He did it in the following way.
if (jsonResponse.getString(DataManager.Name).equals("null")
edtName.setText("");
else
edtName.setText(jsonResponse.getString(usersDataInfo.getNombre()));
But when the field comes with information, it enters the instruction again and removes the information.
JSON
"ID": 23,
"NOMBRE": null,
"APELLIDOPATERNO": null,
"APELLIDOMATERNO": null,
"TELEFONO": null,
"CELULAR": null,
"NACIMIENTO": null,
"SEXO": null,
"USUARIOID": 7
android json android-edittext
Is there any way I can eliminate the "null" string of an editing text brought from a JSONObject response? and just show the empty EditText.
He did it in the following way.
if (jsonResponse.getString(DataManager.Name).equals("null")
edtName.setText("");
else
edtName.setText(jsonResponse.getString(usersDataInfo.getNombre()));
But when the field comes with information, it enters the instruction again and removes the information.
JSON
"ID": 23,
"NOMBRE": null,
"APELLIDOPATERNO": null,
"APELLIDOMATERNO": null,
"TELEFONO": null,
"CELULAR": null,
"NACIMIENTO": null,
"SEXO": null,
"USUARIOID": 7
android json android-edittext
android json android-edittext
edited Mar 6 at 19:34
Skizo-ozᴉʞS
9,5661247105
9,5661247105
asked Mar 6 at 18:00
Gregorio TancitaroGregorio Tancitaro
254
254
Can you post an example of your Json please?
– Skizo-ozᴉʞS
Mar 6 at 18:09
"ID": 23, "NOMBRE": null, "APELLIDOPATERNO": null, "APELLIDOMATERNO": null, "TELEFONO": null, "CELULAR": null, "NACIMIENTO": null, "SEXO": null, "USUARIOID": 7
– Gregorio Tancitaro
Mar 6 at 19:33
I added an answer :)
– Skizo-ozᴉʞS
Mar 6 at 19:48
I would suggest to use Gson or something similar for parsing between json and objects. then you can do a null check on object.
– Arutha
Mar 6 at 20:50
add a comment |
Can you post an example of your Json please?
– Skizo-ozᴉʞS
Mar 6 at 18:09
"ID": 23, "NOMBRE": null, "APELLIDOPATERNO": null, "APELLIDOMATERNO": null, "TELEFONO": null, "CELULAR": null, "NACIMIENTO": null, "SEXO": null, "USUARIOID": 7
– Gregorio Tancitaro
Mar 6 at 19:33
I added an answer :)
– Skizo-ozᴉʞS
Mar 6 at 19:48
I would suggest to use Gson or something similar for parsing between json and objects. then you can do a null check on object.
– Arutha
Mar 6 at 20:50
Can you post an example of your Json please?
– Skizo-ozᴉʞS
Mar 6 at 18:09
Can you post an example of your Json please?
– Skizo-ozᴉʞS
Mar 6 at 18:09
"ID": 23, "NOMBRE": null, "APELLIDOPATERNO": null, "APELLIDOMATERNO": null, "TELEFONO": null, "CELULAR": null, "NACIMIENTO": null, "SEXO": null, "USUARIOID": 7
– Gregorio Tancitaro
Mar 6 at 19:33
"ID": 23, "NOMBRE": null, "APELLIDOPATERNO": null, "APELLIDOMATERNO": null, "TELEFONO": null, "CELULAR": null, "NACIMIENTO": null, "SEXO": null, "USUARIOID": 7
– Gregorio Tancitaro
Mar 6 at 19:33
I added an answer :)
– Skizo-ozᴉʞS
Mar 6 at 19:48
I added an answer :)
– Skizo-ozᴉʞS
Mar 6 at 19:48
I would suggest to use Gson or something similar for parsing between json and objects. then you can do a null check on object.
– Arutha
Mar 6 at 20:50
I would suggest to use Gson or something similar for parsing between json and objects. then you can do a null check on object.
– Arutha
Mar 6 at 20:50
add a comment |
2 Answers
2
active
oldest
votes
Use the method isNull() to check for null value.
i.e:
if (jsonResponse.isNull("NOMBRE"))
edtName.setText("")
else
edtName.setText(jsonResponse.getString("NOMBRE"))
or in case your returning someting, simply:
jsonResponse.isNull("CELULAR") ? (return someting) : (return another thing)
add a comment |
I've created a sample and for me it's working, take a look :
public class MainActivity extends AppCompatActivity
private EditText etEjemplo;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etEjemplo = findViewById(R.id.etEjemplo);
String json = "n" +
"t"ID": 23,n" +
"t"NOMBRE": null,n" +
"t"APELLIDOPATERNO": null,n" +
"t"APELLIDOMATERNO": null,n" +
"t"TELEFONO": null,n" +
"t"CELULAR": null,n" +
"t"NACIMIENTO": null,n" +
"t"SEXO": null,n" +
"t"USUARIOID": 7n" +
"";
try
JSONObject jObj = new JSONObject(json);
String nombre = jObj.getString("NOMBRE");
//You can use jObj.isNull("NOMBRE") instead
if(nombre.equals("null"))
etEjemplo.setText("");
else
etEjemplo.setText(nombre);
//One line case
//etEjemplo.setText(nombre.equals("null") ? "" : nombre);
//or
//etEjemplo.setText(jObj.isNull("NOMBRE") ? "" : nombre);
catch (JSONException e)
e.printStackTrace();
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55029505%2fedittext-how-to-remove-null-string-obtained-from-a-json%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use the method isNull() to check for null value.
i.e:
if (jsonResponse.isNull("NOMBRE"))
edtName.setText("")
else
edtName.setText(jsonResponse.getString("NOMBRE"))
or in case your returning someting, simply:
jsonResponse.isNull("CELULAR") ? (return someting) : (return another thing)
add a comment |
Use the method isNull() to check for null value.
i.e:
if (jsonResponse.isNull("NOMBRE"))
edtName.setText("")
else
edtName.setText(jsonResponse.getString("NOMBRE"))
or in case your returning someting, simply:
jsonResponse.isNull("CELULAR") ? (return someting) : (return another thing)
add a comment |
Use the method isNull() to check for null value.
i.e:
if (jsonResponse.isNull("NOMBRE"))
edtName.setText("")
else
edtName.setText(jsonResponse.getString("NOMBRE"))
or in case your returning someting, simply:
jsonResponse.isNull("CELULAR") ? (return someting) : (return another thing)
Use the method isNull() to check for null value.
i.e:
if (jsonResponse.isNull("NOMBRE"))
edtName.setText("")
else
edtName.setText(jsonResponse.getString("NOMBRE"))
or in case your returning someting, simply:
jsonResponse.isNull("CELULAR") ? (return someting) : (return another thing)
edited Mar 6 at 20:01
answered Mar 6 at 19:39
S. SouzaS. Souza
856
856
add a comment |
add a comment |
I've created a sample and for me it's working, take a look :
public class MainActivity extends AppCompatActivity
private EditText etEjemplo;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etEjemplo = findViewById(R.id.etEjemplo);
String json = "n" +
"t"ID": 23,n" +
"t"NOMBRE": null,n" +
"t"APELLIDOPATERNO": null,n" +
"t"APELLIDOMATERNO": null,n" +
"t"TELEFONO": null,n" +
"t"CELULAR": null,n" +
"t"NACIMIENTO": null,n" +
"t"SEXO": null,n" +
"t"USUARIOID": 7n" +
"";
try
JSONObject jObj = new JSONObject(json);
String nombre = jObj.getString("NOMBRE");
//You can use jObj.isNull("NOMBRE") instead
if(nombre.equals("null"))
etEjemplo.setText("");
else
etEjemplo.setText(nombre);
//One line case
//etEjemplo.setText(nombre.equals("null") ? "" : nombre);
//or
//etEjemplo.setText(jObj.isNull("NOMBRE") ? "" : nombre);
catch (JSONException e)
e.printStackTrace();
add a comment |
I've created a sample and for me it's working, take a look :
public class MainActivity extends AppCompatActivity
private EditText etEjemplo;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etEjemplo = findViewById(R.id.etEjemplo);
String json = "n" +
"t"ID": 23,n" +
"t"NOMBRE": null,n" +
"t"APELLIDOPATERNO": null,n" +
"t"APELLIDOMATERNO": null,n" +
"t"TELEFONO": null,n" +
"t"CELULAR": null,n" +
"t"NACIMIENTO": null,n" +
"t"SEXO": null,n" +
"t"USUARIOID": 7n" +
"";
try
JSONObject jObj = new JSONObject(json);
String nombre = jObj.getString("NOMBRE");
//You can use jObj.isNull("NOMBRE") instead
if(nombre.equals("null"))
etEjemplo.setText("");
else
etEjemplo.setText(nombre);
//One line case
//etEjemplo.setText(nombre.equals("null") ? "" : nombre);
//or
//etEjemplo.setText(jObj.isNull("NOMBRE") ? "" : nombre);
catch (JSONException e)
e.printStackTrace();
add a comment |
I've created a sample and for me it's working, take a look :
public class MainActivity extends AppCompatActivity
private EditText etEjemplo;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etEjemplo = findViewById(R.id.etEjemplo);
String json = "n" +
"t"ID": 23,n" +
"t"NOMBRE": null,n" +
"t"APELLIDOPATERNO": null,n" +
"t"APELLIDOMATERNO": null,n" +
"t"TELEFONO": null,n" +
"t"CELULAR": null,n" +
"t"NACIMIENTO": null,n" +
"t"SEXO": null,n" +
"t"USUARIOID": 7n" +
"";
try
JSONObject jObj = new JSONObject(json);
String nombre = jObj.getString("NOMBRE");
//You can use jObj.isNull("NOMBRE") instead
if(nombre.equals("null"))
etEjemplo.setText("");
else
etEjemplo.setText(nombre);
//One line case
//etEjemplo.setText(nombre.equals("null") ? "" : nombre);
//or
//etEjemplo.setText(jObj.isNull("NOMBRE") ? "" : nombre);
catch (JSONException e)
e.printStackTrace();
I've created a sample and for me it's working, take a look :
public class MainActivity extends AppCompatActivity
private EditText etEjemplo;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etEjemplo = findViewById(R.id.etEjemplo);
String json = "n" +
"t"ID": 23,n" +
"t"NOMBRE": null,n" +
"t"APELLIDOPATERNO": null,n" +
"t"APELLIDOMATERNO": null,n" +
"t"TELEFONO": null,n" +
"t"CELULAR": null,n" +
"t"NACIMIENTO": null,n" +
"t"SEXO": null,n" +
"t"USUARIOID": 7n" +
"";
try
JSONObject jObj = new JSONObject(json);
String nombre = jObj.getString("NOMBRE");
//You can use jObj.isNull("NOMBRE") instead
if(nombre.equals("null"))
etEjemplo.setText("");
else
etEjemplo.setText(nombre);
//One line case
//etEjemplo.setText(nombre.equals("null") ? "" : nombre);
//or
//etEjemplo.setText(jObj.isNull("NOMBRE") ? "" : nombre);
catch (JSONException e)
e.printStackTrace();
edited Mar 6 at 19:49
answered Mar 6 at 19:44
Skizo-ozᴉʞSSkizo-ozᴉʞS
9,5661247105
9,5661247105
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55029505%2fedittext-how-to-remove-null-string-obtained-from-a-json%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you post an example of your Json please?
– Skizo-ozᴉʞS
Mar 6 at 18:09
"ID": 23, "NOMBRE": null, "APELLIDOPATERNO": null, "APELLIDOMATERNO": null, "TELEFONO": null, "CELULAR": null, "NACIMIENTO": null, "SEXO": null, "USUARIOID": 7
– Gregorio Tancitaro
Mar 6 at 19:33
I added an answer :)
– Skizo-ozᴉʞS
Mar 6 at 19:48
I would suggest to use Gson or something similar for parsing between json and objects. then you can do a null check on object.
– Arutha
Mar 6 at 20:50