这个问题在这里已有答案:
是否可以将jstl / JSP变量转换为javascript变量?
这是JSTL:
<c:forEach var="responseString" items = "${responseString}">
<c:out value="${responseString.response}" />
</c:forEach>
我想将 $ 中的值传输到javascript var response
这里是javascript函数:
directionsService.route(请求,功能(响应,状态)
我试过这个教程;
var response = {
<c:forEach var="responseString" items = "${responseString}">
<c:out value="${responseString.response}" />
</c:forEach>
}
显然它没有用,我有点搞砸了,请帮忙 .
添加信息,$ 实际上是 JSON
,我刚将其转换为 String
:
{“routes”:[{“bounds”:{“northeast”:{“lat”:14.650,“lng”:121.050610},“status”:“OK”}
这是一个深深嵌套的 JSON
.
2 回答
做这样的事情:
请注意,您不应为最后一个条目添加“,”,也不应添加单引号
由于你使用的每一个,我认为它将是多个响应,因此你应该使用数组
[]
. 尝试:请注意每个元素后面的
,
.edit on request:
response[i]
将像{"routes": [{"bounds" : {"northeast":{"lat":14.650,"lng":121.050610}, "status":"OK"}
.