PDA

View Full Version : unterminated string literal - jSON



Bivoigt
3 May 2010, 5:54 AM
I'd like to know what's the problem with my code.


,"fluxo": "${fluxo.txtFluxoSimples}"

I have a problem in this line that the JSON don't read when the text appear in this variable. The example about the text is:


,"fluxo": "Scanner UP - I23013
File the...
"}

I saw that the text contains \n and \r or both, but I don't know how I procedure.


,"fluxo": " Fujitsu fi-6240
Configuration about...
"}

Thanks attention....

brianm8675309
3 May 2010, 3:11 PM
You could either strip those "\r" and "\n" characters out on the server side if you do not need them, or if you do, replace them with the html equivalent <br/>.

Bivoigt
4 May 2010, 5:05 AM
So I discovered that the text in my variable return \r\n and too \n in some parts of text. What can I do? It's necessary for me return the text in this format.

Animal
4 May 2010, 6:39 AM
Use a JSON library to generate the JSON text from the object graph.

Bivoigt
4 May 2010, 6:44 AM
I fixed it. Below what I did


<% pageContext.setAttribute("newLineChar","\n");
pageContext.setAttribute("newLineChar2","\r");
pageContext.setAttribute("newLineChar3","\"");
%>
<c:set var="txt" value="${fn:replace(fluxo.txtFluxoSimples,newLineChar,' ')}"></c:set>
<c:set var="txt2" value="${fn:replace(txt,newLineChar2,' ')}"></c:set>
<c:set var="txt3" value="${fn:replace(txt2,newLineChar3,' ')}"></c:set>
,"fluxo": "${txt3}"</c:forEach>


It's enough! ;)

Thanks everybody!