Code example for JSONObject: Parsing JSON documents

Methods: getJSONArraygetJSONObject

0
import org.json.JSONWriter; 
 
import com.google.refine.Jsonizable; 
import com.google.refine.ProjectManager; 
import com.google.refine.ProjectMetadata; 
import com.google.refine.model.Project; 
import com.google.refine.util.JSONUtilities; 
 
 
public class ImportingJob implements Jsonizable { 
    final public long id;
    final public File dir; // Temporary directory where the data about this job is stored
     
    private JSONObject config;
     
    public Project project;
    public ProjectMetadata metadata;
     
    public long lastTouched;
    public boolean updating;
    public boolean canceled;
     
    final private Object lock = new Object();
     
    public ImportingJob(long id, File dir) {
        this.id = id;
        this.dir = dir;
 
        JSONObject cfg = new JSONObject();
        JSONUtilities.safePut(cfg, "state", "new");
        JSONUtilities.safePut(cfg, "hasData", false);
        this.config = cfg;
         
        dir.mkdirs();
    } 
     
     
    public JSONObject getOrCreateDefaultConfig() {
        return config;
    } 
     
    public void setState(String state) {
        synchronized(config) {
            JSONUtilities.safePut(config, "state", state);        
        } 
    } 
 
    public void setError(List<Exception> exceptions) {
        synchronized(config) {
            JSONUtilities.safePut(config, "errors", 
                    DefaultImportingController.convertErrorsToJsonArray(exceptions));
            setState("error"); 
        } 
    } 
     
    public void setProjectID(long projectID) {
        synchronized (config) {
            JSONUtilities.safePut(config, "projectID", projectID);
        } 
    } 
 
    public void setProgress(int percent, String message) {
        synchronized (config) {
            JSONObject progress = JSONUtilities.getObject(config, "progress");
            if (progress == null) {
                progress = new JSONObject();
                JSONUtilities.safePut(config, "progress", progress);
            } 
            JSONUtilities.safePut(progress, "message", message);