Diese Konversation wurde aufgrund von Inaktivität geschlossen. Bitte erstellen Sie einen neuen Post.
Level 1
Level 2
Melden Sie sich an, um alle Badges zu sehen
Diese Konversation wurde aufgrund von Inaktivität geschlossen. Bitte erstellen Sie einen neuen Post.
I have json object. I want to parse it in sightly JS. Which API to use ?
Gelöst! Gehe zu Lösung.
Zugriffe
Antworten
Likes gesamt
Zugriffe
Antworten
Likes gesamt
If you have a JSON string you can use:
var object = JSON.parse(jsonString);
And then use the object to refer to the properties.
If you are using JS-Use API then its ultimately JS at the end and parsing it is nothing but simply using the keys to get desired value out of JSON.
If you are using Java-Use API then the one I have been using to map JSON to java objects is GSON. GSON is pretty handy in converting JSON to JAVA Object and vice-versa.
- Runal
Zugriffe
Antworten
Likes gesamt
Zugriffe
Antworten
Likes gesamt
This doesn't work for me, I have tried this following is js code
"use strict";
use(function() {
var pages = {};
pages.text = properties.get("pages");
pages.ctas = JSON.parse(properties.get("pages"));
return pages;
});
When I call this in html
<div data-sly-use.pages="card.js">
<p> Json text ${pages.text}</p>
<p> CTAs : ${pages.ctas}</p>
</div
I get ${pages.text} displayed however ${pages.ctas} throws exception in error.log
07.07.2015 18:06:41.554 *ERROR* [0:0:0:0:0:0:0:1 [1436306801283] GET /content/veritas/en/testpage.html HTTP/1.1] com.day.cq.wcm.core.impl.WCMDeveloperModeFilter Error during include of SlingRequestPathInfo: path='/content/veritas/en/testpage/jcr:content/par/card', selectorString='null', extension='html', suffix='null'
org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: org.mozilla.javascript.EcmaError: SyntaxError: Unexpected token: L (/apps/veritas/components/content/card/card.html#5)
Zugriffe
Antworten
Likes gesamt
Can you print what is inside properties.get("pages")?
thanks,
feike
Zugriffe
Antworten
Likes gesamt
Use Handlebars. There's no explicit api to parse json directly in sightly. Instead you can dump the json in a handlebar template which can display the json data.
Zugriffe
Antworten
Likes gesamt
Zugriffe
Likes
Antworten
Zugriffe
Likes
Antworten
Zugriffe
Likes
Antworten