YAJT
About
Tutorial
Links
Sourceforge
Getting Started
Tutto è racchiuso in due package principali:
net.sourceforge.yajtnet.sourceforge.yajt.impl
Cominciamo quindi con il
JSONObject, l'elemento fondamentale. Ottenerne una istanza è semplicissimo:
JSONObject myObj = JSONFactory.newObject();Il
JSONObject è sommariamente, una "mappa" di chiavi-valori, dove le chiavi sono stringhe, i valori possono essere qualsiasi oggetto definito nell'implementazione della VM che si sta utilizzando:
myObj.put("myId": new Integer(123));
myObj.put("mySmalltext": "sample text");
myObj.put("myBooleanvalue": Boolean.TRUE);
myObj.put("myNullValue": null);
myObj.put("myDate": new java.util.Date());
Il secondo oggetto fondamentale nella manipolazione di strutture dati JSON è la definizione di JSONArray, una sorta
di java.util.List con alcune limitazioni, che può immagazzinare oggetti di qualsiasi natura, compresi JSONObject come da definizione:
JSONArray myArr = JSONFactory.newArray();
myArr.addElement(new java.util.Date());
myArr.addElement(new Integer(123));
myArr.addElement("sample text");
myArr.addElement(Boolean.TRUE);
myArr.addElement(null);
JSONObject mySecondObj = JSONFactory.newObject();
myArr.addElement(mySecondObj);
myObj.put("myArray", myArr);
Attenzione: Si suppone che le strutture dati che andranno man mano a costruirsi non siano cicliche, come potrebberlo essere per esempio:
myArr.addElement(myObj);
myObj.myObj.put("myArray", myArr);
Versioni future di yajt conterranno controlli affinchè cioò non avvenga, comunque al momento questo codice malevolo
potrebbe generare dei loop infiniti in fase di serializzazione.
Home
Download
Changes
ToDo
Who we are
Legal
Getting started
Parsing
The JSON query path
Event Handling and Serialization
The JSON format
