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?










0















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










share|improve this question
























  • 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















0















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










share|improve this question
























  • 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













0












0








0


0






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










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












2 Answers
2






active

oldest

votes


















1














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)





share|improve this answer
































    1














    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();









    share|improve this answer
























      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
      );



      );













      draft saved

      draft discarded


















      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









      1














      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)





      share|improve this answer





























        1














        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)





        share|improve this answer



























          1












          1








          1







          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)





          share|improve this answer















          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)






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 6 at 20:01

























          answered Mar 6 at 19:39









          S. SouzaS. Souza

          856




          856























              1














              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();









              share|improve this answer





























                1














                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();









                share|improve this answer



























                  1












                  1








                  1







                  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();









                  share|improve this answer















                  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();










                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 6 at 19:49

























                  answered Mar 6 at 19:44









                  Skizo-ozᴉʞSSkizo-ozᴉʞS

                  9,5661247105




                  9,5661247105



























                      draft saved

                      draft discarded
















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                      Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                      Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved