سؤال

لا بد لي من بناء نص من jsonobject و قالب.يبدو أن القالب مثل هذا: giveacodicetagpre.

القالب ليس ثابتا.أعني، يمكن للعميل إرسال أي نوع من الكيانات (التي يتمتع منها jsonobject unmarshalled) والقوالب المناسبة لهذه.

أود استخدام ognel على jsonobject التنقل عبر الرسم البياني للكائن.ولكن هل هناك أي حلول أخرى مثل XSTL ل JSON؟شيء آخر مثل هذا؟

هل كانت مفيدة؟

المحلول

If you can live with a slightly different syntax for the template, perhaps mustache would do it. It is available for multiple languages, including Java and JavaScript. -> http://mustache.github.com/

نصائح أخرى

Instead of using org.json's simplistic lib, you could upgrade to a better JSON library (such as Jackson), bind data as regular Maps (Lists, Numbers etc), and then most templating engines could access things as expected.

Or even use full data binding to POJOs with setters, getters, if you need to access data from Java code as well.

PURE transforms JSON data into HTML. Works standalone or with dojo, DomAssistant, jQuery, Mootools, Prototype, Sizzle and Sly

HTML template

<div class="who">
</div>

JSON Data

{
  "who": "Hello Wrrrld"
}

Run the code

Hello Wrrrld

See more info see http://beebole.com/pure/

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top