JSON for all (almost!)

Read this post to learn how you can support JSON in the following:

  • JavaScript
  • jQuery
  • .NET (C#)
  • PHP
  • Delphi

JavaScript: (http://en.wikipedia.org/wiki/JSON)

JSON.parse(...);     //String to Object
JSON.stringify(...); //Object to String

* Native JSON support for Mozilla Firefox 3.5+, Microsoft Internet Explorer 8+, Opera 10.5+, WebKit-based browsers (Apple Safari), Blink – based browsers (e.g. Google Chrome, Opera). For older browsers use this: https://github.com/douglascrockford/JSON-js

jQuery: (http://api.jquery.com/jQuery.parseJSON/)

jQuery.parseJSON(...); //String to Object

* Object to String not supported, use JSON.stringify(). Infact, you should always use JSON.parse and JSON.stringify

.NET (C#):

using System.Web.Script.Serialization;
var json = new JavaScriptSerializer().Serialize(...);//Object to String
var obj = new JavaScriptSerializer().Deserialize(...);//String to Object

* Native support for .NET Framework 3.5+. More reading here: http://msdn.microsoft…javascriptserializer.aspx. A more complete library for JSON, supporting all .NET versions can be found here http://json.codeplex.com/

PHP:(http://php.net/manual/en/book.json.php)

$json = json_encode(...); //Object to String
$obj = json_decode(...);  //String to Object

Delphi
There is no native support for JSON but you can use this: http://sourceforge.net/projects/lkjson/

Advertisements

One thought on “JSON for all (almost!)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s