In: ,
On: 2009 / 05 / 07 Viewed: 37878 times
Shorter URL for this post: http://ozh.in/lu

Encoding an array to JSON is dead easy on PHP 5.2+: you just use PHP’s function json_encode(). The thing is, WordPress has pretty loose requirements and is designed to run on older PHP builds. For those, you need a third party library that will encode to (and decode from, if you need) JSON.

The cool news is that you don’t have to bother searching for such a reliable library: WordPress comes with its own. Just include() the file located at /wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php and you’re good.

Check more details and examples on KAPISH.

Related posts

Shorter URL

Want to share or tweet this post? Please use this short URL: http://ozh.in/lu

Metastuff

This entry "Encoding JSON with WordPress" was posted on 07/05/2009 at 11:09 pm and is tagged with ,
Watch this discussion : Comments RSS 2.0.

One Reply

  1. 1
    Barry Spain »
    commented, on 30/May/09 at 12:22 am # :

    Good find Ozh, that will come in useful for PHP4 compatibility for my API plugin.

Leave a Reply

Comment Guidelines or Die

  • HTML: You can use these tags: <a href=""> <em> <i> <b> <strong> <blockquote>
  • Posting code: Post raw code (no <> &lt; etc) within appropriate tags : [php][/php], [css][/css], [html][/html], [js][/js], [sql][/sql], [xml][/xml], or generic [code][code]
  • Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar.
  • Spam: Various spam plugins on patrol. I'll put pins in a Voodoo doll if you spam me.
  • I will mark as Spam test comments, all comments with SEO names (ie "My Cool Online Shop" instead of "Joe") or containing forum-like signatures.

Read more ?

Close
E-mail It