javascript - push object to array and eventually convert array to json -


i creating object , pushing array.then convert json.when alert datacharts returned as:

[{"alllinks":"link9","linkurl":"url1"},{"alllinks":"link6","linkurl":"url2"}] 

whereas want as:

[{alllinks:"link9",linkurl:"url1"},{alllinks:"link6",linkurl:"url2"}] 

my code follows:

  $.ajax({      url:  url,      type: "get",      headers: {"accept": "application/json;odata=verbose"},      success: function (data) {          var array = new array();          var temp = new object();          (var i=0; i< data.d.results.length; i++) {              var it=data.d.results[i];              array.push({                  "alllinks": it.alllinks,                    "linkurl": it.linkurl.url              });          }          datacharts=json.stringify(array);               alert(datacharts);          adddefaultlinks(datacharts);      },      error: function (data) {          alert(data.responsejson.error);      }  }); 

hint:

[{"_aaaa_":"bbbb","_cccc_":"eeee"}] [{aaaa:"bbbb",cccc:"eeee"}] 

if want remove quotes: name label this:

_alllinks_: it.alllinks,    _linkurl_: it.linkurl.url 

and remove underscores , quotes this:

datacharts.replace(/"_|_"/g,"")    

but carefull not conflict other data (or take 2 _ or so)


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -