對不起,如果這是轉發,但我發佈後無法找到我的問題。我有一個軌道應用程序呈現一個JSON字符串,並在數據庫中存儲相同的刺痛。接收輸出的初始頁面的輸出和顯示來自db的數據的頁面具有不同的輸出。數據和格式化數據的功能是相同的。我很難過。從JSON.stringify輸出不一致輸出
功能:
function prettyPrint(jsonStr) {
var jsonObj = jQuery.parseJSON(jsonStr);
return '<pre>' + JSON.stringify(jsonObj,null,'\t') + '</pre>';
}
數據:
{"Account":{"account_id":1},"response_details":[],"return_code":200,"Devices":[{"imei":"1234","name":"Device 1"},{"imei":"54321","name":"device 3"},{"imei":"354476024650842","name":"device 4 [no data]"},{"imei":"55124","name":"BlackBerry (8800)"},{"imei":"1234567890","name":"Garmin Sample"},{"imei":"987654321","name":"Second Garmin"},{"imei":"546787545678","name":"Tower 1"}]}
輸出1:(從AJAX)
{
"Account": {
"account_id": 1
},
"response_details": [],
"return_code": 200,
"Devices": [
{
"imei": "1234",
"name": "Device 1"
},
{
"imei": "54321",
"name": "device 3"
},
{
"imei": "354476024650842",
"name": "device 4 [no data]"
},
{
"imei": "55124",
"name": "BlackBerry (8800)"
},
{
"imei": "1234567890",
"name": "Garmin Sample"
},
{
"imei": "987654321",
"name": "Second Garmin"
},
{
"imei": "546787545678",
"name": "Tower 1"
}
]
}
輸出2:(從分貝)
{
"Account": {
"account_id": 1
},
"response_details": "[]",
"return_code": 200,
"Devices": "[{\"imei\": \"1234\", \"name\": \"Device 1\"}, {\"imei\": \"54321\", \"name\": \"device 3\"}, {\"imei\": \"354476024650842\", \"name\": \"device 4 [no data]\"}, {\"imei\": \"55124\", \"name\": \"BlackBerry (8800)\"}, {\"imei\": \"1234567890\", \"name\": \"Garmin Sample\"}, {\"imei\": \"987654321\", \"name\": \"Second Garmin\"}, {\"imei\": \"546787545678\", \"name\": \"Tower 1\"}]"
}
你在使用輸出從DB結果代碼?它是一個存儲過程,服務器端腳本?我需要並排查看代碼,找出造成差異的原因。 – Adam 2010-09-13 18:50:41
我將檢索到的數據傳遞給相同的js函數以寫入div。 – 2010-09-13 19:02:31