這對你們中的一些人來說,這可能是一個簡單的問題。但我只是沒有如何做到這一點,我需要幫助。這裏是我的JSON:parse json jquery
{"name":"cust_num","comparison":"starts_with","value":"01"},
{"name":"cust_name","comparison":"starts_with","value":"ad"},
{"name":"cust_age","comparison":"=","value":"20"}
我的程序JSON提醒這樣的:
{
"ID":"TBsKI7",
"dataType":"data",
"filters":[
"{\"name\":\"cust_num\",\"comparison\":\"starts_with\",\"value\":\"01\"}",
"{\"name\":\"cust_name\",\"comparison\":\"starts_with\",\"value\":\"ad\"}",
"{\"name\":\"cust_age\",\"comparison\":\"=\",\"value\":\"20\"}
],
"recordLimit":50,
"recordOffset":0,
.
.
.
}
這顯然是一個錯誤。在我看來,第一個json被串化了兩次(如果我正確地使用該術語)。現在,我想要的是如何糾正我的第一個JSON,或者如何解析它,以便它不會輸出'\'。
我已經嘗試過使用jQuery.parseJson(),但它返回null。
感謝您的閱讀。
EDIT: 這是我的JavaScript代碼產生上述JSON:
$('#table tr').each(function(){
var td = '';
if ($(this).find("td:first").length > 0) { // used to skip table header (if there is)
$(this).find('option:selected').each(function(){
td = td + $(this).text()+ ',';
});
td = td + $(this).find('input').val();
filt[ctr]=td;
ctr += 1;
}
});
for (var i = 0;i<filt.length;i++) {
b = filt[i].split(',');
if (b[0] == "no"){
b[0] = "cust_num";
}
if (b[0] == "name"){
b[0] = "cust_name";
}
if (b[0] == "age"){
b[0] = "cust_age";
}
jsonobj.name = b[0];
jsonobj.comparison = b[1];
jsonobj.value = b[2];
c[i] = JSON.stringify(jsonobj); //if json.stringify, it will display the json with '\'
//if not, its only the last filter will be read for all the tr.
}
我有一個動態表,其將接受,我將用於創建JSON數據。
這是不是你的整個JSON。看起來你在嵌套對象..我們可以有整個代碼片段嗎? – 2011-05-10 07:43:15
我認爲你的第一個問題是無論產生那個JSON。與其試圖修補它,我會盡力確保它的正確性。 JSON從哪裏來? – Dve 2011-05-10 07:49:25
@David和@Dve ...請參閱我的編輯。感謝您的快速回復:) – jayAnn 2011-05-10 07:52:55