Skip to content

BUG:字符串的错误 #4

@ghost

Description

当字符串里面本身带有引号时,json->string方法输出的格式有问题。需要对字符串进行转换处理。
使用你的core库解决此问题。

$ git diff -w HEAD 
diff --git a/json.sc b/json.sc
index 29f92e1..6748fd3 100644
--- a/json.sc
+++ b/json.sc
@@ -36,6 +36,7 @@
   (import
     (scheme)
     (only (core alist) vector->alist)
+    (only (core string) string-replace)
   )
  
 
@@ -131,7 +132,7 @@
       (define f
         (lambda (x)
           (cond                          
-            ((string? x) (string-append "\"" x "\""))                       
+            ((string? x) (string-append "\"" (string-replace x "\"" "\\\"") "\""))
             ((number? x) (number->string x))                        
             ((symbol? x) (symbol->string x)))))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions