0
我使用以下CouchDB設計文檔進行測試。我使用回車符\ n和製表符\ t來縮進我的Javascript代碼。據我瞭解JSON,我認爲這些地方的空白是好的。但是Ruby couchrest也無法解析這個和JSLint。在解析它之前,我必須從設計文檔中去除\ n和\ t。這是爲什麼 ?Jouch解析CouchDB設計文檔時出錯:由於縮進空格而導致未關閉的字符串?
上json.org的JSON介紹頁提到,「空白可以在任何一令牌之間插入。」
這是一個有點難以這裏呈現的標籤,所以我已經包括瞭解析字符串\ n和T。
{
"_id": "_design/test",
"views": {
"all": {
"map": "function(doc) {
if (doc.nom) emit(doc._id, doc);
}"
},
"asin_doc": {
"map": "function(doc) {
if (doc.category) emit(doc.asin, doc);
}"
},
"asin": {
"map": "function(doc) {
if (doc.category) emit(doc.asin, null);
}"
}
}
}
在一個長字符串(紅寶石)的同一個文件:
"{\n\t\"_id\": \"_design/test\",\n\t\"views\": {\n\t\t\"all\": {\n\t\t\t\"map\": \"function(doc) {\n\t\t\t\tif (doc.nom) emit(doc._id, doc);\n\t\t\t}\"\n\t\t},\n\t\t\"asin_doc\": {\n\t\t\t\"map\": \"function(doc) {\n\t\t\t\tif (doc.category) emit(doc.asin, doc);\n\t\t\t}\"\n\t\t},\n\t\t\"asin\": {\n\t\t\t\"map\": \"function(doc) {\n\t\t\t\tif (doc.category) emit(doc.asin, null);\n\t\t\t}\"\n\t\t}\n\t}\n}\n"
JSLint的告訴我,有5行字的問題20
Problem at line 5 character 20: Unclosed string.
"map": "function(doc) {
Problem at line 5 character 20: Stopping. (25% scanned).
JSON: bad.
我不能看看字符串沒有正確關閉的地方。任何想法 ?