Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/shinovon/NNJSON

JSON library for Java, compatible with CLDC 1.1 & JDK 1.1
https://github.com/shinovon/NNJSON

j2me json json-library

Last synced: 4 months ago
JSON representation

JSON library for Java, compatible with CLDC 1.1 & JDK 1.1

Awesome Lists containing this project

README

        

# cc.nnproject.json
JSON library for Java, compatible with CLDC 1.1 & JDK 1.1

## Usage example:

`JSON`:
```
JSONObject json = JSON.getObject(str);
System.out.println(json.getArray("messages").getObject(0).getNullableString("text"));
```

`JSONArray`, `JSONObject`:
```
JSONArray objects = new JSONArray();

JSONObject object1 = new JSONObject();
object1.put("some", "Example text");
objects.add(object1);

JSONObject object2 = new JSONObject();
object2.put("n", 292);
objects.add(object2);

System.out.println(objects.build());
```

`JSONStream`:
```
JSONStream stream = JSONStream.getStream(connection.openInputStream());
try {
stream.expectNextTrim('{');

if(!stream.jumpToKey("response")) return;
stream.expectNextTrim('{');

if(!stream.jumpToKey("items")) return;
stream.expectNextTrim('[');

if(!stream.skipArrayElements(3)) return;
stream.expectNextTrim('{');

if(!stream.jumpToKey("date")) return;

System.out.println(stream.nextValue());
} finally {
stream.close();
}
```