Parsing JSON Values Through jQuery is eliminating 1st value

Multi tool use
Multi tool use












0















I am storing a PHP array variable in Jquery variable.



Following is the code that I am using:



<script>
var tagger = '<?php echo json_encode($tags); ?>';
var obj = jQuery.parseJSON(tagger);
$.each(obj, function(key,value)
{
$("#post_tags").tagging("add", value);
});
</script>


In tagger variable, I am getting this below data.



var tagger = '["sdf"," da"," adf"," ad"]';


But when I am running the loop it is showing values from the second index, the first index value is being eliminated.



Only these values are visible in the field : '[" da"," adf"," ad"]'.

The sdf value is not displayed.



May I know that where is it being wrong, as far as I am concerned the code is good to go. But still, want to confirm that is there anything missing.










share|improve this question





























    0















    I am storing a PHP array variable in Jquery variable.



    Following is the code that I am using:



    <script>
    var tagger = '<?php echo json_encode($tags); ?>';
    var obj = jQuery.parseJSON(tagger);
    $.each(obj, function(key,value)
    {
    $("#post_tags").tagging("add", value);
    });
    </script>


    In tagger variable, I am getting this below data.



    var tagger = '["sdf"," da"," adf"," ad"]';


    But when I am running the loop it is showing values from the second index, the first index value is being eliminated.



    Only these values are visible in the field : '[" da"," adf"," ad"]'.

    The sdf value is not displayed.



    May I know that where is it being wrong, as far as I am concerned the code is good to go. But still, want to confirm that is there anything missing.










    share|improve this question



























      0












      0








      0








      I am storing a PHP array variable in Jquery variable.



      Following is the code that I am using:



      <script>
      var tagger = '<?php echo json_encode($tags); ?>';
      var obj = jQuery.parseJSON(tagger);
      $.each(obj, function(key,value)
      {
      $("#post_tags").tagging("add", value);
      });
      </script>


      In tagger variable, I am getting this below data.



      var tagger = '["sdf"," da"," adf"," ad"]';


      But when I am running the loop it is showing values from the second index, the first index value is being eliminated.



      Only these values are visible in the field : '[" da"," adf"," ad"]'.

      The sdf value is not displayed.



      May I know that where is it being wrong, as far as I am concerned the code is good to go. But still, want to confirm that is there anything missing.










      share|improve this question
















      I am storing a PHP array variable in Jquery variable.



      Following is the code that I am using:



      <script>
      var tagger = '<?php echo json_encode($tags); ?>';
      var obj = jQuery.parseJSON(tagger);
      $.each(obj, function(key,value)
      {
      $("#post_tags").tagging("add", value);
      });
      </script>


      In tagger variable, I am getting this below data.



      var tagger = '["sdf"," da"," adf"," ad"]';


      But when I am running the loop it is showing values from the second index, the first index value is being eliminated.



      Only these values are visible in the field : '[" da"," adf"," ad"]'.

      The sdf value is not displayed.



      May I know that where is it being wrong, as far as I am concerned the code is good to go. But still, want to confirm that is there anything missing.







      php jquery json






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 30 '18 at 20:02









      Shahnewaz

      426311




      426311










      asked Dec 30 '18 at 11:26









      Akshay ShrivastavAkshay Shrivastav

      503421




      503421
























          2 Answers
          2






          active

          oldest

          votes


















          1














          <script>
          // try this
          var obj = <?php echo json_encode($tags); ?>;
          //var obj = jQuery.parseJSON(tagger);
          $.each(obj, function(key,value)
          {
          $("#post_tags").tagging("add", value);
          });
          </script>





          share|improve this answer
























          • still the same thing

            – Akshay Shrivastav
            Dec 30 '18 at 11:40











          • what does console.log(obj) gives in console

            – Shantanu Terang
            Dec 30 '18 at 11:42











          • (4) ["sdf", " da", " adf", " ad"] 0: "sdf" 1: " da" 2: " adf" 3: " ad" length: 4 __proto__: Array(0)

            – Akshay Shrivastav
            Dec 30 '18 at 11:50













          • one more error i spotted Uncaught TypeError: f[b] is not a function at HTMLDivElement.<anonymous> (tagging.min.js:223) at Function.each (jquery-3.3.1.min.js:2) at w.fn.init.each (jquery-3.3.1.min.js:2) at w.fn.init.e.fn.tagging (tagging.min.js:220) at HTMLDocument.<anonymous> (post.js:149) at l (jquery-3.3.1.min.js:2) at c (jquery-3.3.1.min.js:2)

            – Akshay Shrivastav
            Dec 30 '18 at 11:50



















          0














          You don't have to parse the tagger because it already in json format:



          <script>
          var tagger = <?php echo json_encode((array)$tags);?>;
          $.each(tagger, function(key,value)
          {
          $("#post_tags").tagging("add", value);
          });
          </script>





          share|improve this answer


























          • i tried doing this, it gives the following error Uncaught TypeError: Cannot use 'in' operator to search for 'length' in ["sdf"," da"," adf"," ad"]

            – Akshay Shrivastav
            Dec 30 '18 at 11:36











          • try the edited answer

            – McBern
            Dec 30 '18 at 11:41











          • still the same error

            – Akshay Shrivastav
            Dec 30 '18 at 11:49











          • can you var_dump the $tags?

            – McBern
            Dec 30 '18 at 11:52











          • array (size=4) 0 => string 'sdf' (length=3) 1 => string ' da' (length=3) 2 => string ' adf' (length=4) 3 => string ' ad' (length=3)

            – Akshay Shrivastav
            Dec 30 '18 at 11:56











          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%2f53977209%2fparsing-json-values-through-jquery-is-eliminating-1st-value%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














          <script>
          // try this
          var obj = <?php echo json_encode($tags); ?>;
          //var obj = jQuery.parseJSON(tagger);
          $.each(obj, function(key,value)
          {
          $("#post_tags").tagging("add", value);
          });
          </script>





          share|improve this answer
























          • still the same thing

            – Akshay Shrivastav
            Dec 30 '18 at 11:40











          • what does console.log(obj) gives in console

            – Shantanu Terang
            Dec 30 '18 at 11:42











          • (4) ["sdf", " da", " adf", " ad"] 0: "sdf" 1: " da" 2: " adf" 3: " ad" length: 4 __proto__: Array(0)

            – Akshay Shrivastav
            Dec 30 '18 at 11:50













          • one more error i spotted Uncaught TypeError: f[b] is not a function at HTMLDivElement.<anonymous> (tagging.min.js:223) at Function.each (jquery-3.3.1.min.js:2) at w.fn.init.each (jquery-3.3.1.min.js:2) at w.fn.init.e.fn.tagging (tagging.min.js:220) at HTMLDocument.<anonymous> (post.js:149) at l (jquery-3.3.1.min.js:2) at c (jquery-3.3.1.min.js:2)

            – Akshay Shrivastav
            Dec 30 '18 at 11:50
















          1














          <script>
          // try this
          var obj = <?php echo json_encode($tags); ?>;
          //var obj = jQuery.parseJSON(tagger);
          $.each(obj, function(key,value)
          {
          $("#post_tags").tagging("add", value);
          });
          </script>





          share|improve this answer
























          • still the same thing

            – Akshay Shrivastav
            Dec 30 '18 at 11:40











          • what does console.log(obj) gives in console

            – Shantanu Terang
            Dec 30 '18 at 11:42











          • (4) ["sdf", " da", " adf", " ad"] 0: "sdf" 1: " da" 2: " adf" 3: " ad" length: 4 __proto__: Array(0)

            – Akshay Shrivastav
            Dec 30 '18 at 11:50













          • one more error i spotted Uncaught TypeError: f[b] is not a function at HTMLDivElement.<anonymous> (tagging.min.js:223) at Function.each (jquery-3.3.1.min.js:2) at w.fn.init.each (jquery-3.3.1.min.js:2) at w.fn.init.e.fn.tagging (tagging.min.js:220) at HTMLDocument.<anonymous> (post.js:149) at l (jquery-3.3.1.min.js:2) at c (jquery-3.3.1.min.js:2)

            – Akshay Shrivastav
            Dec 30 '18 at 11:50














          1












          1








          1







          <script>
          // try this
          var obj = <?php echo json_encode($tags); ?>;
          //var obj = jQuery.parseJSON(tagger);
          $.each(obj, function(key,value)
          {
          $("#post_tags").tagging("add", value);
          });
          </script>





          share|improve this answer













          <script>
          // try this
          var obj = <?php echo json_encode($tags); ?>;
          //var obj = jQuery.parseJSON(tagger);
          $.each(obj, function(key,value)
          {
          $("#post_tags").tagging("add", value);
          });
          </script>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 30 '18 at 11:37









          Shantanu TerangShantanu Terang

          12315




          12315













          • still the same thing

            – Akshay Shrivastav
            Dec 30 '18 at 11:40











          • what does console.log(obj) gives in console

            – Shantanu Terang
            Dec 30 '18 at 11:42











          • (4) ["sdf", " da", " adf", " ad"] 0: "sdf" 1: " da" 2: " adf" 3: " ad" length: 4 __proto__: Array(0)

            – Akshay Shrivastav
            Dec 30 '18 at 11:50













          • one more error i spotted Uncaught TypeError: f[b] is not a function at HTMLDivElement.<anonymous> (tagging.min.js:223) at Function.each (jquery-3.3.1.min.js:2) at w.fn.init.each (jquery-3.3.1.min.js:2) at w.fn.init.e.fn.tagging (tagging.min.js:220) at HTMLDocument.<anonymous> (post.js:149) at l (jquery-3.3.1.min.js:2) at c (jquery-3.3.1.min.js:2)

            – Akshay Shrivastav
            Dec 30 '18 at 11:50



















          • still the same thing

            – Akshay Shrivastav
            Dec 30 '18 at 11:40











          • what does console.log(obj) gives in console

            – Shantanu Terang
            Dec 30 '18 at 11:42











          • (4) ["sdf", " da", " adf", " ad"] 0: "sdf" 1: " da" 2: " adf" 3: " ad" length: 4 __proto__: Array(0)

            – Akshay Shrivastav
            Dec 30 '18 at 11:50













          • one more error i spotted Uncaught TypeError: f[b] is not a function at HTMLDivElement.<anonymous> (tagging.min.js:223) at Function.each (jquery-3.3.1.min.js:2) at w.fn.init.each (jquery-3.3.1.min.js:2) at w.fn.init.e.fn.tagging (tagging.min.js:220) at HTMLDocument.<anonymous> (post.js:149) at l (jquery-3.3.1.min.js:2) at c (jquery-3.3.1.min.js:2)

            – Akshay Shrivastav
            Dec 30 '18 at 11:50

















          still the same thing

          – Akshay Shrivastav
          Dec 30 '18 at 11:40





          still the same thing

          – Akshay Shrivastav
          Dec 30 '18 at 11:40













          what does console.log(obj) gives in console

          – Shantanu Terang
          Dec 30 '18 at 11:42





          what does console.log(obj) gives in console

          – Shantanu Terang
          Dec 30 '18 at 11:42













          (4) ["sdf", " da", " adf", " ad"] 0: "sdf" 1: " da" 2: " adf" 3: " ad" length: 4 __proto__: Array(0)

          – Akshay Shrivastav
          Dec 30 '18 at 11:50







          (4) ["sdf", " da", " adf", " ad"] 0: "sdf" 1: " da" 2: " adf" 3: " ad" length: 4 __proto__: Array(0)

          – Akshay Shrivastav
          Dec 30 '18 at 11:50















          one more error i spotted Uncaught TypeError: f[b] is not a function at HTMLDivElement.<anonymous> (tagging.min.js:223) at Function.each (jquery-3.3.1.min.js:2) at w.fn.init.each (jquery-3.3.1.min.js:2) at w.fn.init.e.fn.tagging (tagging.min.js:220) at HTMLDocument.<anonymous> (post.js:149) at l (jquery-3.3.1.min.js:2) at c (jquery-3.3.1.min.js:2)

          – Akshay Shrivastav
          Dec 30 '18 at 11:50





          one more error i spotted Uncaught TypeError: f[b] is not a function at HTMLDivElement.<anonymous> (tagging.min.js:223) at Function.each (jquery-3.3.1.min.js:2) at w.fn.init.each (jquery-3.3.1.min.js:2) at w.fn.init.e.fn.tagging (tagging.min.js:220) at HTMLDocument.<anonymous> (post.js:149) at l (jquery-3.3.1.min.js:2) at c (jquery-3.3.1.min.js:2)

          – Akshay Shrivastav
          Dec 30 '18 at 11:50













          0














          You don't have to parse the tagger because it already in json format:



          <script>
          var tagger = <?php echo json_encode((array)$tags);?>;
          $.each(tagger, function(key,value)
          {
          $("#post_tags").tagging("add", value);
          });
          </script>





          share|improve this answer


























          • i tried doing this, it gives the following error Uncaught TypeError: Cannot use 'in' operator to search for 'length' in ["sdf"," da"," adf"," ad"]

            – Akshay Shrivastav
            Dec 30 '18 at 11:36











          • try the edited answer

            – McBern
            Dec 30 '18 at 11:41











          • still the same error

            – Akshay Shrivastav
            Dec 30 '18 at 11:49











          • can you var_dump the $tags?

            – McBern
            Dec 30 '18 at 11:52











          • array (size=4) 0 => string 'sdf' (length=3) 1 => string ' da' (length=3) 2 => string ' adf' (length=4) 3 => string ' ad' (length=3)

            – Akshay Shrivastav
            Dec 30 '18 at 11:56
















          0














          You don't have to parse the tagger because it already in json format:



          <script>
          var tagger = <?php echo json_encode((array)$tags);?>;
          $.each(tagger, function(key,value)
          {
          $("#post_tags").tagging("add", value);
          });
          </script>





          share|improve this answer


























          • i tried doing this, it gives the following error Uncaught TypeError: Cannot use 'in' operator to search for 'length' in ["sdf"," da"," adf"," ad"]

            – Akshay Shrivastav
            Dec 30 '18 at 11:36











          • try the edited answer

            – McBern
            Dec 30 '18 at 11:41











          • still the same error

            – Akshay Shrivastav
            Dec 30 '18 at 11:49











          • can you var_dump the $tags?

            – McBern
            Dec 30 '18 at 11:52











          • array (size=4) 0 => string 'sdf' (length=3) 1 => string ' da' (length=3) 2 => string ' adf' (length=4) 3 => string ' ad' (length=3)

            – Akshay Shrivastav
            Dec 30 '18 at 11:56














          0












          0








          0







          You don't have to parse the tagger because it already in json format:



          <script>
          var tagger = <?php echo json_encode((array)$tags);?>;
          $.each(tagger, function(key,value)
          {
          $("#post_tags").tagging("add", value);
          });
          </script>





          share|improve this answer















          You don't have to parse the tagger because it already in json format:



          <script>
          var tagger = <?php echo json_encode((array)$tags);?>;
          $.each(tagger, function(key,value)
          {
          $("#post_tags").tagging("add", value);
          });
          </script>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 30 '18 at 12:03

























          answered Dec 30 '18 at 11:34









          McBernMcBern

          520147




          520147













          • i tried doing this, it gives the following error Uncaught TypeError: Cannot use 'in' operator to search for 'length' in ["sdf"," da"," adf"," ad"]

            – Akshay Shrivastav
            Dec 30 '18 at 11:36











          • try the edited answer

            – McBern
            Dec 30 '18 at 11:41











          • still the same error

            – Akshay Shrivastav
            Dec 30 '18 at 11:49











          • can you var_dump the $tags?

            – McBern
            Dec 30 '18 at 11:52











          • array (size=4) 0 => string 'sdf' (length=3) 1 => string ' da' (length=3) 2 => string ' adf' (length=4) 3 => string ' ad' (length=3)

            – Akshay Shrivastav
            Dec 30 '18 at 11:56



















          • i tried doing this, it gives the following error Uncaught TypeError: Cannot use 'in' operator to search for 'length' in ["sdf"," da"," adf"," ad"]

            – Akshay Shrivastav
            Dec 30 '18 at 11:36











          • try the edited answer

            – McBern
            Dec 30 '18 at 11:41











          • still the same error

            – Akshay Shrivastav
            Dec 30 '18 at 11:49











          • can you var_dump the $tags?

            – McBern
            Dec 30 '18 at 11:52











          • array (size=4) 0 => string 'sdf' (length=3) 1 => string ' da' (length=3) 2 => string ' adf' (length=4) 3 => string ' ad' (length=3)

            – Akshay Shrivastav
            Dec 30 '18 at 11:56

















          i tried doing this, it gives the following error Uncaught TypeError: Cannot use 'in' operator to search for 'length' in ["sdf"," da"," adf"," ad"]

          – Akshay Shrivastav
          Dec 30 '18 at 11:36





          i tried doing this, it gives the following error Uncaught TypeError: Cannot use 'in' operator to search for 'length' in ["sdf"," da"," adf"," ad"]

          – Akshay Shrivastav
          Dec 30 '18 at 11:36













          try the edited answer

          – McBern
          Dec 30 '18 at 11:41





          try the edited answer

          – McBern
          Dec 30 '18 at 11:41













          still the same error

          – Akshay Shrivastav
          Dec 30 '18 at 11:49





          still the same error

          – Akshay Shrivastav
          Dec 30 '18 at 11:49













          can you var_dump the $tags?

          – McBern
          Dec 30 '18 at 11:52





          can you var_dump the $tags?

          – McBern
          Dec 30 '18 at 11:52













          array (size=4) 0 => string 'sdf' (length=3) 1 => string ' da' (length=3) 2 => string ' adf' (length=4) 3 => string ' ad' (length=3)

          – Akshay Shrivastav
          Dec 30 '18 at 11:56





          array (size=4) 0 => string 'sdf' (length=3) 1 => string ' da' (length=3) 2 => string ' adf' (length=4) 3 => string ' ad' (length=3)

          – Akshay Shrivastav
          Dec 30 '18 at 11:56


















          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%2f53977209%2fparsing-json-values-through-jquery-is-eliminating-1st-value%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







          962 A,D2OysqU2ylpzl5xbxcIu1 2cemhkxzl6UY,fVHG0G,o4AFeJc,63SMmpLEiuWXCxZR
          h3HiQLC05ku6zPnEmvlJV2,H08zBbXLgYUu2JgVmKiQZYnUlcfYi3VX5eSWj2u0tCAQ

          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas