I have String object with template base, something like:
<h1>{{header}}</h1>
{{#bug}}
{{/bug}}
{{#items}}
{{#first}}
<li><strong>{{name}}</strong></li>
{{/first}}
{{#link}}
<li><a href="{{url}}">{{name}}</a></li>
{{/link}}
{{/items}}
{{#empty}}
<p>The list is empty.</p>
{{/empty}}
I want to pull another String object representing JSONObject and put its fields into template:
{
"header": "Colors",
"items": [
{"name": "red", "first": true, "url": "#Red"},
{"name": "green", "link": true, "url": "#Green"},
{"name": "blue", "link": true, "url": "#Blue"}
],
"empty": false
}
In the end I would get String representing HTML structure:
<h1>Colors</h1>
<li><strong>red</strong></li>
<li><a href="#Green">green</a></li>
<li><a href="#Blue">blue</a></li>
I don’t want to use any POJOs or Maps – only use standard String objects or alternatively convert second String into JSONObject to use it as a template’s context.
Could someone give me any example how to achieve that?
Thanks.
Edit: I don’t know anything about template/JSON structure while executing template – I have to play with unknown template/JSON and assume that they are correct.
I couldn’t find way to work on pure
Stringobjects – I am convertingJSONObjecttoMapto get it working with Mustache. This is code for conversion:Usage: