Ad

Uncaught TypeError: Cannot Use 'in' Operator To Search For '123' In

Hi i have converted json object to string by using JSON.stringify now i want key value pair in array for eg. key =en value =Anglais and so on...
here is jsfiddle
code

      var data ={"en":{"name":"Anglais"},"fr":{"name":"Français"},
"it":{"name":"Italien"},"de":{"name":"Allemand"},"es":{"name":"Espagnol"}}

I have done so far

      var data = {
      "en": {
          "name": "Anglais"
      },
      "fr": {
          "name": "Français"
      },
          "it": {
          "name": "Italien"
      },
      "de": {
          "name": "Allemand"
      },
      "es": {
          "name": "Espagnol"
      }
  };
  var strData = JSON.stringify(data);
  for (var i = 0; i < strData.length; i++) {
      $('#dvarray').append('string array==' + strData[i] + "<br>");
  }
  $.each(strData, function (key, value) {

      var abbr = JSON.stringify(value);

       $('#dvstring').html('abbr=' + abbr.substr(2, 4)); //Uncaught TypeError:

  });
Ad

Answer

this helped me

  var data = {
      "en": {
          "name": "Anglais"
      },
      "fr": {
          "name": "Français"
      },
          "it": {
          "name": "Italien"
      },
      "de": {
          "name": "Allemand"
      },
      "es": {
          "name": "Espagnol"
      }
  };

for(var prop in data) {
   $('#dvstring').append( prop + "    <>     " + data[prop].name +  "<br>") ;
}
  $.each(strData, function (key, value) {

      var abbr = JSON.stringify(value);

       $('#dvstring').append('abbr=' + abbr.substr(2, 4));     
  });
Ad
source: stackoverflow.com
Ad