Wednesday, January 25, 2017

boost ptree

This is an awesome post on how to use ptree for json processing. http://zenol.fr/blog/boost-property-tree/en.html

Thursday, January 12, 2017

JSON in Java

Add to your Maven dependency
1
2
3
4
5
<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.json</artifactId>
    <version>1.0.4</version>
</dependency>
Demo:
1
2
3
4
5
6
7
String json = "{\"id\":3}";
JsonReader reader = Json.createReader(new StringReader(json));
JsonObject rootObject = reader.readObject();
reader.close();

int devID = rootObject.getInt("id");
String sDevID = Integer.toString(devID);