User Tools

Site Tools


en:xjson

This is an old revision of the document!


xjson

JSON, JavaScript Object Notation, is a string presentation of a JavaScript object so that JavaScript object can be saved in file or exchange among computers. Although is used in JavaScript, it can also be interpreted in other programming languages.

JSON Data Type Limitation

The data type used in JSON are null, number, string, boolean, list, and object. The object specified in JSON is only a “generic” object without speification of object class, it is a list of key-value pairs similar to a dictionary in other languages. Which make some common data type, like Datetime is difficult to specifiy.

Datetime in JavaScript is an object. Although one can specify a Datetime as an object. But the receiver cannot know an object is a Datetime object since there are no class specification in a JSON object.

So how can a receiver know a data is a date, without prior knowledge? A common solution is to send datetime as string. Then the receiver need to decode every string to datetime. If success, it is a date, time, or datetime. If not, it is a normal string.

Alternative, we can provide the object class name in a special attribute, say _cls. The receiver then look for this class attribute on each received object.

en/xjson.1780476991.txt.gzip · Last modified: by administrator