In: ,
On: 2009 / 05 / 07 Viewed: 53778 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.

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. Barry says:

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

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar and sign for a free account
Spam: Various spam plugins may be activated. I'll put pins in a Voodoo doll if you spam me.

Read more ?