GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Processing
  • Download
  • Reference
  • Environment
  • Libraries
  • Tools
  • Wiki
  • Tutorials
  • Examples
  • Books
  • Forum
  • Overview
  • People
  • Privacy

This view

  • Original page
  • New address

GeezerVison is showing www.processing.org — setJSONArray() / Reference

Reference+
Documentation→Reference→Data→Composite→JSONObject

Name

setJSONArray()

Class

JSONObject

Description

Sets the value of the JSONArray with the associated key.

Examples

  • String[] species = { "Capra hircus", "Panthera pardus", "Equus zebra" };
    String[] names = { "Goat", "Leopard", "Zebra" };
    
    JSONObject json;
    
    void setup() {
      
      JSONArray values = new JSONArray();
    
      for (int i = 0; i < species.length; i++) {
    
        JSONObject animal = new JSONObject();
    
        animal.setInt("id", i);
        animal.setString("species", species[i]);
        animal.setString("name", names[i]);
    
        values.setJSONObject(i, animal);
      }
      
      json = new JSONObject();
      json.setJSONArray("animals", values);
    
      saveJSONObject(json, "data/new.json");
    }
    
    // Sketch saves the following to a file called "new.json":
    // {"animals": [
    //   {
    //     "id": 0,
    //     "species": "Capra hircus",
    //     "name": "Goat"
    //   },
    //   {
    //     "id": 1,
    //     "species": "Panthera pardus",
    //     "name": "Leopard"
    //   },
    //   {
    //     "id": 2,
    //     "species": "Equus zebra",
    //     "name": "Zebra"
    //   }
    // ]}
    

Syntax

  • .setJSONArray(key, value)

Parameters

  • key(String)a key string
  • value(JSONArray)value to assign

Return

  • JSONObject

Related

  • JSONObject::setJSONObject()
  • JSONObject::getJSONObject()
  • JSONObject::getJSONArray()
Creative Commons License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.