Example usage for org.json JSONArray JSONArray

List of usage examples for org.json JSONArray JSONArray

Introduction

In this page you can find the example usage for org.json JSONArray JSONArray.

Prototype

public JSONArray() 

Source Link

Document

Construct an empty JSONArray.

Usage

From source file:game.objects.Board.java

public JSONArray getBoardJSON() throws JSONException {
    JSONArray arr = new JSONArray();
    for (String key : countries.keySet()) {
        JSONObject json = new JSONObject();
        json.put("CountryID", key);
        json.put("CountryName", countries.get(key).getName());
        json.put("Owner", countries.get(key).getOwner());
        json.put("Troops", countries.get(key).getTroops());
        arr.put(json);/*from  ww  w.j  a v a  2  s .  co m*/
    }
    return arr;
}

From source file:ai.susi.mind.SusiArgument.java

public JSONObject toJSON() {
    JSONObject json = new JSONObject(true);
    JSONArray recallJson = new JSONArray();
    this.recall.forEach(thought -> recallJson.put(thought));
    JSONArray actionsJson = new JSONArray();
    this.actions.forEach(action -> actionsJson.put(action.toJSONClone()));
    json.put("recall", recallJson);
    json.put("action", actionsJson);
    return json;//from www .  j  ava2  s .  com
}

From source file:com.ecml.MidiOptions.java

/** Convert this MidiOptions object into a JSON string. */
public String toJson() {
    try {/*from   ww w  .ja va  2s . co m*/
        JSONObject json = new JSONObject();
        JSONArray jsonTracks = new JSONArray();
        for (boolean value : tracks) {
            jsonTracks.put(value);
        }
        JSONArray jsonMute = new JSONArray();
        for (boolean value : mute) {
            jsonMute.put(value);
        }
        JSONArray jsonInstruments = new JSONArray();
        for (int value : instruments) {
            jsonInstruments.put(value);
        }
        if (time != null) {
            JSONObject jsonTime = new JSONObject();
            jsonTime.put("numerator", time.getNumerator());
            jsonTime.put("denominator", time.getDenominator());
            jsonTime.put("quarter", time.getQuarter());
            jsonTime.put("tempo", time.getTempo());
            json.put("time", jsonTime);
        }

        json.put("versionCode", 7);
        json.put("tracks", jsonTracks);
        json.put("mute", jsonMute);
        json.put("instruments", jsonInstruments);
        json.put("useDefaultInstruments", useDefaultInstruments);
        json.put("scrollVert", scrollVert);
        json.put("showPiano", showPiano);
        json.put("showNoteColors", showNoteColors);
        json.put("showLyrics", showLyrics);
        json.put("delay", delay);
        json.put("twoStaffs", twoStaffs);
        json.put("showNoteLetters", showNoteLetters);
        json.put("transpose", transpose);
        json.put("key", key);
        json.put("combineInterval", combineInterval);
        json.put("shade1Color", shade1Color);
        json.put("shade2Color", shade2Color);
        json.put("showMeasures", showMeasures);
        json.put("playMeasuresInLoop", playMeasuresInLoop);
        json.put("playMeasuresInLoopStart", playMeasuresInLoopStart);
        json.put("playMeasuresInLoopEnd", playMeasuresInLoopEnd);

        return json.toString();
    } catch (JSONException e) {
        return null;
    } catch (NullPointerException e) {
        return null;
    }
}

From source file:org.everit.json.schema.EnumSchemaTest.java

@Before
public void before() {
    possibleValues = new HashSet<>();
    possibleValues.add(true);/* w w  w  .  j a v a 2s.c  om*/
    possibleValues.add("foo");
    possibleValues.add(new JSONArray());
    possibleValues.add(new JSONObject("{\"a\" : 0}"));
}

From source file:org.everit.json.schema.EnumSchemaTest.java

@Test
public void success() {
    EnumSchema subject = subject();//from   w ww .  java2  s  .com
    subject.validate(true);
    subject.validate("foo");
    subject.validate(new JSONArray());
    subject.validate(new JSONObject("{\"a\" : 0}"));
}

From source file:com.andybotting.tramhunter.objects.FavouriteList.java

/**
 * Convert an old favourites string to the new JSON format
 * @param favouriteString//w w  w. ja v  a  2  s .  c o  m
 * @return JSONArray
 */
private String convertOldFavourites(String favouriteString) {

    try {
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject;
        int tramTrackerId;

        StringTokenizer tokenizer = new StringTokenizer(favouriteString, ",");
        while (tokenizer.hasMoreTokens()) {
            tramTrackerId = Integer.parseInt(tokenizer.nextToken());
            jsonObject = new JSONObject();
            jsonObject.put("stop", tramTrackerId);
            jsonArray.put(jsonObject);
        }
        return jsonArray.toString();

    } catch (Exception e) {
        e.printStackTrace();
    }

    return "";
}

From source file:com.andybotting.tramhunter.objects.FavouriteList.java

/**
 * Generate a JSON string serializing our favourites
 *//*  w w  w  .j a  v  a 2s  .  c o m*/
public JSONArray getFavouritesJSON() {

    JSONArray jsonArray = new JSONArray();

    for (Favourite favourite : mFavourites) {
        jsonArray.put(favourite.getFavouriteJSON());
    }

    return jsonArray;
}

From source file:de.kp.ames.web.function.transform.cache.XslCacheManager.java

/**
 * This method retrieves the actually uploaded transformators 
 * that are currently not registered in the OASIS ebXML RegRep
 * /*from   w w  w  . j  av a 2  s . c  o m*/
 * @return
 * @throws Exception
 */
public JSONArray getJEntries() throws Exception {

    JSONArray jEntries = new JSONArray();

    List<CacheEntry> transformators = cache.getAll();
    for (int ix = 0; ix < transformators.size(); ix++) {

        XslTransformator transformator = (XslTransformator) transformators.get(ix);
        String key = transformator.getKey();

        JSONObject jTransformator = new JSONObject();

        jTransformator.put(JsonConstants.J_KEY, key);
        jTransformator.put(JsonConstants.J_NAME, transformator.getName());

        jTransformator.put(JsonConstants.J_DESC, "No description available.");
        jTransformator.put(JsonConstants.J_MIME, transformator.getMimetype());

        jEntries.put(jEntries.length(), jTransformator);

    }

    return jEntries;

}

From source file:org.apache.usergrid.chop.webapp.service.chart.series.Series.java

public JSONArray getJsonArray() {

    JSONArray arr = new JSONArray();

    for (Point p : getPoints()) {
        arr.put(p.toJson());
    }

    return arr;
}

From source file:it.acutus.utilitylibrarycode.parser.XmlToJson.java

private JSONObject convertTagToJson(Tag tag) {
    JSONObject json = new JSONObject();

    // Content is injected as a key/value
    if (tag.getContent() != null) {
        try {/*www.  j a  v  a  2 s . com*/
            String path = tag.getPath();
            String name = getContentNameReplacement(path, DEFAULT_CONTENT_NAME);
            json.put(name, tag.getContent());
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    try {
        if (tag.isList() || isForcedList(tag)) {
            JSONArray list = new JSONArray();
            ArrayList<Tag> children = tag.getChildren();
            for (Tag child : children) {
                list.put(convertTagToJson(child));
            }
            String childrenNames = tag.getChild(0).getName();
            json.put(childrenNames, list);
            return json;
        } else {
            ArrayList<Tag> children = tag.getChildren();
            if (children.size() == 0) {
                json.put(tag.getName(), tag.getContent());
            } else {
                for (Tag child : children) {
                    if (child.hasChildren()) {
                        JSONObject jsonChild = convertTagToJson(child);
                        json.put(child.getName(), jsonChild);
                    } else {
                        json.put(child.getName(), child.getContent());
                    }
                }
            }
            return json;
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;
}