I've a JSON containing some HTML contents from an External System. We have a Rich Text field for storing this HTML data. But I noticed, while storing I'm getting some HTML tags included in to the field as the HTML contents are coming as JSON string. So my question is how can I store the received JSON string data as a HTML back in Netsuite field. Is it possible ?
Jdata = dataIn.desc; // getting something like : Guest(s) benifit's surcharges <br><p>test benifit desc 25% discountpop "test"</p>
Thanks for your interest !
Maybe try unescape or decodeuri, which are standard old js methods.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape
If not just do a string replacement on the known char sets (" being the same as ")
Related
I am working on a SpringBoot based MVC application which uses mongoDB to store the data. I am using thymeleaf as the template engine. In one of the scenarios, the user needs to fill a form which is then displayed on some view.
The problem I am facing is that the user can use html tags to format the data while writing in the textArea of the form (code snippets, tabular format etc). But when I am displaying that text, the html is not being parsed and is displayed as is.
For Ex: <b>String</b> should be displayed as String but is being displayed as <b>String</b> only. When I check the source code of the page, the html tags are displayed as encoded i.e. < is showing as < ; etc and hence the parsing is not happening.
Can someone please help
You can output unescaped text with th:utext. From the official turorial
If we want Thymeleaf to respect our XHTML tags and not escape them, we will have to use a different attribute: th:utext (for “unescaped text”):
<p th:utext="#{home.welcome}">Welcome to our grocery store!</p>
The tutorial assumes that home.welcome is a string with html-tags:
home.welcome=Welcome to our <b>fantastic</b> grocery store!.
It goes without saying that this needs very careful validation so that only safe (whatever safe is for the particular use case) HTML is stored into the database (and no possibly malicious code like <script/> tags).
I would like my webpage to display what resembles JASON Parser
does (right panel). I first installed JSONView on my Chrome.
Then I composed a string {"isbn":"asdf","name":"qwer","price":1} which I fed to JSON Parser and made sure it indeed obeyed JSON format.
Eventually, I attempted to display it on my webpage by doing:
out.println("{\"isbn\":\"asdf\",\"name\":\"qwer\",\"price\":1}\");
but it was simply displayed like any other normal String instead of being formatted like this.
How do I manage to make my webpage automatically display JSON formatted?
Thanks!
Edit: I didn't realise this was JSP. The answer I'm giving relates to using the JavaScript method JSON.stringify() which you'd somehow achieve within client-side JavaScript within your JSP project.
Use JSON.stringify() to 'pretty-print' the original JavaScript object.
For example, to have two spaces of indentation:
var str = JSON.stringify(obj, null, 2);
If this has to be achieved within Java code then you could use the GSON library. Example: Pretty-Print JSON in Java
Classic problem. Want to see html rendered but I'm seeing text in the browser. Whether I tell handlebars js to decode it or not in template ( three curly braces vs two - {{{myHtmlData}}} vs {{myHtmlData}} ) doesn't get me there. Something about the JSON being returned via the model.fetch() has this html data wrapped up in such a way that it is resistant to the notion of displaying as HTML. It's always considered a string whether encoded or decoded so it always displays as text.
Is this just something backbone isn't meant to do?
The technologies involved here are:
backbone.marionette
handlebars.js
.NET Web API
Your data is being escaped automatically. It's a good thing, but since you're sure the data is a safe HTML. Use {{{}}} as in this other question Insert html in a handlebar template without escaping .
When I try to show the JSON string, the indentation is gone and very ugly.
Is there a way to make it look better?
As you stated in a comment : the JSON string looks good in a browser. That is propably (I'm 99% sure) because most browsers will recognize the content as JSON and display it nicely, in an easier to read form. But in its core, the JSON string is just a set of characters, without any special whitespace characters like /n or /t to indicate newlines or tabs.
So to answear your question : in order to display your JSON string similarily to what you see in your browser, you'd have to parse and format it yourself.
If you are using a CCLabel to display it, you could subclass it creating a JSONLabel which would format a string given in its constructor the way that you like it.
I am using LINQ-to-XML. I am building a small program that helps parse HTML. I'd like to save the HTML tags into an XML file, but I don't want the XML file to check the validity of the entered HTML elements.
How can I just entere a simple string literal (a pretty long one)?
Maybe using a CDATA construct could help you out, see w3schools.com