Package org.json

Examples of org.json.JSONArray


import org.json.JSONObject;

public class VKGrabber {
  private static String getVKStream(final String json) {
    final JSONObject jsonObj = new JSONObject(json);
    final JSONArray response = jsonObj.getJSONArray("response");
    for (final int i = 0; i < response.length();) {
      final Object jsonObject = response.get(i);
      final JSONObject jsonResults = new JSONObject(jsonObject.toString());
      final String stream = jsonResults.getString("url");
      return stream;

    }
View Full Code Here


  public static String buildSearchCSV(final String json) {
    final StringBuilder csv = new StringBuilder()
        .append("Title, Artist, Duration, URL, id");
    csv.append(System.getProperty("line.separator"));
    final JSONObject mainObject = new JSONObject(json);
    final JSONArray response = mainObject.getJSONArray("response");
    for (int i = 0; i < response.length(); i++) {
      if (i == 0) {
        continue;
      }
      final Object jsonObject = response.get(i);
      final JSONObject jsonResults = new JSONObject(jsonObject.toString());
      final int duration = jsonResults.getInt("duration");

      String artist = jsonResults.getString("artist");
      String title = jsonResults.getString("title");
View Full Code Here

   * @param stringy
   *            true if the first element is a string.
   * @throws JSONException
   */
  private JSONArray readArray(final boolean stringy) throws JSONException {
    final JSONArray jsonarray = new JSONArray();
    jsonarray.put(stringy ? read(this.stringhuff, this.stringhuffext,
        this.stringkeep) : readValue());
    while (true) {
      if (probe) {
        log();
      }
      if (!bit()) {
        if (!bit()) {
          return jsonarray;
        }
        jsonarray.put(stringy ? readValue() : read(this.stringhuff,
            this.stringhuffext, this.stringkeep));
      } else {
        jsonarray.put(stringy ? read(this.stringhuff,
            this.stringhuffext, this.stringkeep) : readValue());
      }
    }
  }
View Full Code Here

    case zipArrayValue:
      return readArray(false);
    case zipEmptyObject:
      return new JSONObject();
    case zipEmptyArray:
      return new JSONArray();
    case zipTrue:
      return Boolean.TRUE;
    case zipFalse:
      return Boolean.FALSE;
    default:
View Full Code Here

      write(zipTrue, 3);
    } else {
      if (value instanceof Map) {
        value = new JSONObject((Map<String, Object>) value);
      } else if (value instanceof Collection) {
        value = new JSONArray((Collection<Object>) value);
      } else if (value.getClass().isArray()) {
        value = new JSONArray(value);
      }
      if (value instanceof JSONObject) {
        write((JSONObject) value);
      } else if (value instanceof JSONArray) {
        write((JSONArray) value);
View Full Code Here

    // Load config file
    String[] config = p.loadStrings(configFilePath);
    String data = PApplet.join(config, "");
    myJsonObject = new JSONObject(data);
   
    JSONArray json = myJsonObject.getJSONArray("components");
    for (int i = 0; i < json.length(); i++) {
      JSONObject childJSONObject = json.getJSONObject(i);
      this.add(new Component(childJSONObject));
    }
  }
View Full Code Here

    }
    IStorage indexFile = getProjectTemplatesIndexIStorage();
    try{
      if(!indexFile.exists()) {
        this.projectTemplatesIndex = new JSONObject();
        JSONArray templates = new JSONArray();
        this.projectTemplatesIndex.put("templates", templates);
      }else{
        String indexFileContents = readFile(indexFile.getPath());
        this.projectTemplatesIndex = new JSONObject(indexFileContents);
      }
View Full Code Here

    }
    try{
      // Filter the list of templates
      IPerson person = user.getPerson();
      String userEmail = person.getEmail();     
      JSONArray allTemplates = returnObject.getJSONArray("templates");
      JSONArray userTemplates = new JSONArray();
      int count = allTemplates.length();
      for(int i=0 ; i< count; i++){
        JSONObject template = allTemplates.getJSONObject(i);
        String authorEmail = template.getString("authorEmail");
        String sharing = template.getString("sharingSimple");
        if(userEmail.equals(authorEmail) || (this.enableProjectSharingAll && sharing.equals("all"))){
          userTemplates.put(template);
        }
      }
      returnObject.put("templates", userTemplates);
      return returnObject;
    } catch (JSONException e) {
View Full Code Here

        }
      }
     
      // Remove any templates from index that match this template
      JSONObject projectTemplatesObject = _getProjectTemplatesIndex();
      JSONArray oldTemplates;
      oldTemplates = projectTemplatesObject.getJSONArray("templates");
      JSONArray newTemplates = new JSONArray();
      JSONObject template;
      String oldCreationTimestamp = null;
      int count = oldTemplates.length();
      for(int i=0 ; i< count; i++){
        template = oldTemplates.getJSONObject(i);
        String folder = template.getString("folder");
        if(folder.equals(templateFolderName)){
          oldCreationTimestamp = template.getString("creationTimestamp");
        }else{
          newTemplates.put(template);
        }
      }
      // Add this template and write out a new copy of index file
      template = new JSONObject();
      template.put("folder", templateFolderName);
      template.put("name", projectTemplateName);
      template.put("authorEmail", email);
      template.put("clonedProject", projectToClone);
      template.put("sharingSimple", sharingSimple);
      template.put("creationTimestamp", oldCreationTimestamp == null ? timestamp : oldCreationTimestamp);
      template.put("lastModifyTimestamp", timestamp);
      newTemplates.put(template);
     
      updateTemplates(newTemplates);

    } catch (JSONException e) {
      String desc = "addProjectTemplate - json exception";
View Full Code Here

    String errorString = null;
    IPerson person = user.getPerson();
    String email = person.getEmail();

    JSONObject projectTemplatesObject;
    JSONArray existingTemplates;
    try{
      IStorage projectTemplatesDirectory = getProjectTemplatesDirectory();
      projectTemplatesObject = _getProjectTemplatesIndex();
      existingTemplates = projectTemplatesObject.getJSONArray("templates");
      // Verify that all of the templatesToDelete exist
      // and are owned by this user
      int count = templatesToDelete.length();
      for(int i=0 ; i< count; i++){
        JSONObject templateToDelete = templatesToDelete.getJSONObject(i);
        int found = findTemplateInArray(existingTemplates, templateToDelete, email);
        if(found == -1){
          return "at least one template to delete not found";
        }
      }
     
      // Delete the overridden template(s), both in the index file
      // and on disk
      JSONArray newTemplates = new JSONArray();
      int existingCount = existingTemplates.length();
      for(int j=0; j<existingCount; j++){
        JSONObject existingTemplate = existingTemplates.getJSONObject(j);
        String existingName = existingTemplate.getString("name");
        String existingEmail = existingTemplate.getString("authorEmail");
        Boolean found = false;
        int deleteCount = templatesToDelete.length();
        for(int i=0 ; i< deleteCount; i++){
          JSONObject templateToDelete = templatesToDelete.getJSONObject(i);
          String deleteName = templateToDelete.getString("name");
          if(existingName.equals(deleteName) && existingEmail.equals(email)){
            found = true;
            break;
          }
        }
        if(found){
          String existingFolderName = makeProjectTemplateFolderName(existingName, existingEmail);
          IStorage existingFolder = projectTemplatesDirectory.newInstance(projectTemplatesDirectory, existingFolderName);
          deleteDirectory(existingFolder);
        }else{
          newTemplates.put(existingTemplate);
        }
      }
      updateTemplates(newTemplates);
    } catch (JSONException e) {
      String desc = "deleteProjectTemplates - json exception";
View Full Code Here

TOP

Related Classes of org.json.JSONArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.