2016-04-19 66 views
1

我想通過在遊戲框架視圖如何通過Scala的地圖[字符串,地圖[字符串,字符串]]以普通JavaScript對象

斯卡拉值映射到JavaScript的JSON onject我得到「語法錯誤:JSON。解析:意外的字符在1號線JSON數據」的第10列當我檢查下面的代碼

val mapTobePassToJs = Map(

     "cg1" -> Map(
     "path" -> "/var/logs/cdr1/cdr", 
     "name" -> "CG-1" 

    ), 

     "cg2" -> Map(
     "path" -> "/var/logs/cdr2/cdr", 
     "name" -> "CG-2" 
    ), 

     "cg3" -> Map(
     "path" -> "/var/logs/cdr3/cdr", 
     "name" -> "CG-3" 
    ), 

     "cg4" -> Map(
     "path" -> "/var/logs/cdr3/cdr", 
     "name" -> "CG-4" 
    ) 
    ) 

<script type="text/javascript"> 

     var aChartList = jQuery.parseJSON("@JSONObject(mapTobePassToJs).toString()".replace(/&quot;/g,'"')); 

</script> 

請人幫我

回答

3

當你想JSON作爲一個結果,你爲什麼不使用Json.obj()。那麼以下將是你的結構。

val mapTobePassToJs = Json.obj(

     "cg1" -> Json.obj(
     "path" -> "/var/logs/cdr1/cdr", 
     "name" -> "CG-1" 

    ), 

     "cg2" -> Json.obj(
     "path" -> "/var/logs/cdr2/cdr", 
     "name" -> "CG-2" 
    ), 

     "cg3" -> Json.obj(
     "path" -> "/var/logs/cdr3/cdr", 
     "name" -> "CG-3" 
    ), 

     "cg4" -> Json.obj(
     "path" -> "/var/logs/cdr3/cdr", 
     "name" -> "CG-4" 
    ) 
    ) 
+0

感謝您的建議 – Muhunthan

+0

歡迎您:)快樂編程! –

相關問題