Code example for JSONObject

Methods: get, getString, has, isNull

0
    } 
     
    static protected Node reconstructNode(JSONObject o) throws JSONException {
        Node node = null;
         
        String nodeType = o.getString("nodeType");
        if (nodeType.startsWith("cell-as-")) {
            if ("cell-as-topic".equals(nodeType)) {
                if (o.has("type")) {
                    node = new CellTopicNode(
                        reconstructType(o.getJSONObject("type"))
                    ); 
                } 
            } else if ("cell-as-value".equals(nodeType)) {
                node = new CellValueNode(
                    o.getString("valueType"),
                    o.getString("lang")
                ); 
            } else if ("cell-as-key".equals(nodeType)) {
                node = new CellKeyNode(
                    reconstructTopic(o.getJSONObject("namespace"))
                ); 
            } 
             
            if (o.has("columnName") && !o.isNull("columnName")) {
                ((CellNode) node).columnNames.add(o.getString("columnName"));
            } 
            if (o.has("columnNames") && !o.isNull("columnNames")) {
                JSONArray columnNames = o.getJSONArray("columnNames");
                int count = columnNames.length();
                 
                for (int c = 0; c < count; c++) {
                    ((CellNode) node).columnNames.add(columnNames.getString(c));
                } 
            } 
        } else if ("topic".equals(nodeType)) {
            node = new FreebaseTopicNode(reconstructTopic(o.getJSONObject("topic")));
        } else if ("value".equals(nodeType)) {
            node = new ValueNode(
                o.get("value"),
                o.getString("valueType"),
                o.getString("lang")
            ); 
        } else if ("anonymous".equals(nodeType)) {
            node = new AnonymousNode(reconstructType(o.getJSONObject("type")));
        } 
         
        if (node != null && node instanceof NodeWithLinks && o.has("links")) {
            NodeWithLinks node2 = (NodeWithLinks) node;
             
            JSONArray links = o.getJSONArray("links");
            int linkCount = links.length();