I'm new to java and javascript. I have started using json objects to return data from our SQL server and it's been nice however, I have run into an issue and I am not sure how to approach it. I'm also not even sure if it is possible but it never hurts to ask.
I have a field in a database that is storing HTML content.
<p>Please verify you have done the following before submitting a trouble-ticket</p> <ol> <li>Be sure you are using your correct user name and password (e.e., first initial and last name)</li> <li>Password are case sensitive</li> <li>Be sure to select the domain from the drop-down list.</li> <li>Network cable must be plugged in!</li> </ol>
I am trying to output it to a JSON object so I can display it on screen with it's current formatting.
I build my json object in a .jsp page like so:
if(rs != null && rs.next()){
out.print("{\"qteTips\" : [");
tipList = new StringBuffer();
int rowCount = 0;
String HelpfulTipID = null;
String Title = null;
String Tip = null;
String DateCreated = null;
String Active = null;
do{
rowCount++;
HelpfulTipID = rs.getString("HelpfulTipID");
Title = rs.getString("Title");
DateCreated = rs.getString("DateCreated");
Active = rs.getString("Active");
Tip = rs.getString("Tip");
if(rowCount > 1){
out.print(",");
}
out.print("{\"HelpfulTipID\":\""+HelpfulTipID+"\",");
out.print("\"Title\":\""+Title+"\",");
out.print("\"DateCreated\":\""+DateCreated+"\",");
out.print("\"Active\":\""+Active+"\",");
out.print("\"Tip\":\""+Tip+"\"}");
if(DEBUG){
System.out.println("created record #"+rowCount);
}
}
while(rs != null && rs.next());
out.print("]}");
try {rs.close();} catch (SQLException sqle){}
try{ps.close();} catch (SQLException sqle){}
}else{
out.print("{\"error\":\"No tips found.\"}");
}
But when I grab the object it looks like this:
{"qteTips" : [{"HelpfulTipID":"47","Title":"Unable to login to your comptuer?","DateCreated":"06/01/15","Active":"1","Tip":"<p>Please verify you have done the following before submitting a trouble-ticket</p>
<ol>
<li>Be sure you are using your correct user name and password (e.e., first initial and last name)</li>
<li>Password are case sensitive</li>
<li>Be sure to select the domain from the drop-down list.</li>
<li>Network cable must be plugged in!</li>
</ol>
"}]}
And I get this error on jsonlint.com when attempting to validate it.
Parse error on line 8:
... "Tip": "<p>Please verify yo
----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['
Does anyone know a better approach to what I am trying to do?