如何删除json元素?

I'am using dataTables plugin for my table, and it has an json data from the database like :

{"sEcho":0,
"iTotalRecords":1,
"iTotalDisplayRecords":1,
"aaData":[["contentFieldA","contentFieldB","contentFieldC"],
          ["contentFieldA","contentFieldB","contentFieldC"]],
"sColumns":"fieldA,fieldB,fieldC"}

for some reason I need to remove the "aaData" and "sColumns" value on the first index (so "contentFieldA" and "fieldA" should be removed). and the json data will be :

{"sEcho":0,
 "iTotalRecords":1,
 "iTotalDisplayRecords":1,
 "aaData":[["contentFieldB","contentFieldC"],
           ["contentFieldB","contentFieldC"]],
 "sColumns":"fieldB,fieldC"}

Can anyone help me.. Thanks

If you have :

var test = {"sEcho":0,
"iTotalRecords":1,
"iTotalDisplayRecords":1,
"aaData":[["contentFieldA","contentFieldB","contentFieldC"],
          ["contentFieldA","contentFieldB","contentFieldC"]],
"sColumns":"fieldA,fieldB,fieldC"};

aaData is an array of arrays, so remove first index of each subarray like this :

for (var i=0;i<test['aaData'].length;i++) {
    test['aaData'][i].splice(0,1);
}

deleting first index from sColumns is a little bit harder, since it is a string :

test['sColumns']=test['sColumns'].split(',').splice(1,2).join();

Notice that splice(1,2) is hardcoded, if you have 4 columns it should be splice(1,3), 5 columns splice(1,4) and so on.

Running those two cleanups will give the desired result.

Since it is in JSON, you can use regular expression and remove what you want:

PHP: http://au1.php.net/preg_replace JS: http://www.w3schools.com/jsref/jsref_replace.asp