Hello.
I try to transfer from JSP to JSON.
<c:set var="json_text"> [{"TIME_STAMP": "2016-07-25 02:30:22", "COUNTER": "COUNT_ALL", "VALUE": 635 }, { "TIME_STAMP": "2016-07-25 02:30:22", "COUNTER": "COUNT_BAD", "VALUE": 1 }, { "TIME_STAMP": "2016-07-25 02:30:22", "COUNTER": "QUALITY", "VALUE": 99.84 }, { "TIME_STAMP": "2016-07-25 02:31:22", "COUNTER": "COUNT_ALL", "VALUE": 642 }, { "TIME_STAMP": "2016-07-25 02:31:22", "COUNTER": "COUNT_BAD", "VALUE": 1 }, { "TIME_STAMP": "2016-07-25 02:31:22", "COUNTER": "QUALITY", "VALUE": 99.84 }] </c:set> <script type="text/javascript"> var jsonString='<c:out value="${json_text}"/>'; var jsonObj = JSON.parse(jsonString); </script> Uncaught SyntaxError error reproduced: Unexpected token & in JSON at position 2
BUT if you take and copy the entire content directly into the Java script, then everything works.
<script type="text/javascript"> var jsonString='[{"TIME_STAMP": "2016-07-25 02:30:22", "COUNTER": "COUNT_ALL", "VALUE": 635 }, { "TIME_STAMP": "2016-07-25 02:30:22", "COUNTER": "COUNT_BAD", "VALUE": 1 }, { "TIME_STAMP": "2016-07-25 02:30:22", "COUNTER": "QUALITY", "VALUE": 99.84 }, { "TIME_STAMP": "2016-07-25 02:31:22", "COUNTER": "COUNT_ALL", "VALUE": 642 }, { "TIME_STAMP": "2016-07-25 02:31:22", "COUNTER": "COUNT_BAD", "VALUE": 1 }, { "TIME_STAMP": "2016-07-25 02:31:22", "COUNTER": "QUALITY", "VALUE": 99.84 }]'; var jsonObj = JSON.parse(jsonString); </script> Tell me what the problem is.
ps at first thought that in var jsonString = "; just the string is transmitted, but checked in this way
<script type="text/javascript"> var JSONFromJSTL='<c:out value="${json_text}"/>'; jsonResult.push("Вывод JSON="+JSONFromJSTL); result_json.innerHTML = jsonResult.join('<br>'); </script> at
<div id="result_json"></div> such result is transmitted
JSON = [{"TIME_STAMP": "2016-07-25 02:30:22", "COUNTER": "COUNT_ALL", "VALUE": 635}, {"TIME_STAMP": "2016-07-25 02: 30:22 "," COUNTER ":" COUNT_BAD "," VALUE ": 1}, {" TIME_STAMP ":" 2016-07-25 02:30:22 "," COUNTER ":" QUALITY "," VALUE ": 99.84}, {"TIME_STAMP": "2016-07-25 02:31:22", "COUNTER": "COUNT_ALL", "VALUE": 642}, {"TIME_STAMP": "2016-07-25 02:31 : 22 "," COUNTER ":" COUNT_BAD "," VALUE ": 1}, {" TIME_STAMP ":" 2016-07-25 02:31:22 "," COUNTER ":" QUALITY "," VALUE ": 99.84 }]
those. exactly what is needed.