我想在Play框架视图中将Scala Map值传递给JavaScript JSON onject
我得到“SyntaxError:JSON.parse:JSON数据的第1行第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(/"/g,'"'));
</script>
任何人都请帮助我
答案 0 :(得分:3)
因为你想要Json,你为什么不使用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"
)
)
。以下是你的结构。
var resp = request.GetResponse();