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(Object array) throws JSONException 

Source Link

Document

Construct a JSONArray from an array

Usage

From source file:app.sunstreak.yourpisd.net.Student.java

public void loadClassList() throws IOException {

    String postParams = "{\"studentId\":\"" + studentId + "\"}";

    ArrayList<String[]> requestProperties = new ArrayList<String[]>();
    requestProperties.add(new String[] { "Content-Type", "application/json" });

    HTTPResponse init = Request.sendPost(
            "https://gradebook.pisd.edu/Pinnacle/Gradebook/InternetViewer/InternetViewerService.ashx/Init?PageUniqueId="
                    + session.pageUniqueId,
            session.cookies, requestProperties, true, postParams);

    String response = init.getData();
    int responseCode = init.getResponseCode();

    try {/*from ww w . j a v a 2 s  .c o  m*/
        classList = (new JSONArray(response)).getJSONObject(0).getJSONArray("classes");
    } catch (JSONException e) {
        e.printStackTrace();
        System.out.println(response);
    }

}

From source file:org.jenkinsci.plugins.testrail.TestRailClient.java

public Project[] getProjects() throws IOException, ElementNotFoundException {
    String body = httpGet("/index.php?/api/v2/get_projects").getBody();
    JSONArray json = new JSONArray(body);
    Project[] projects = new Project[json.length()];
    for (int i = 0; i < json.length(); i++) {
        JSONObject o = json.getJSONObject(i);
        Project p = new Project();
        p.setName(o.getString("name"));
        p.setId(o.getInt("id"));
        projects[i] = p;/*www. java  2s  .  c  o m*/
    }
    return projects;
}

From source file:org.jenkinsci.plugins.testrail.TestRailClient.java

public Suite[] getSuites(int projectId) throws IOException, ElementNotFoundException {
    String body = httpGet("/index.php?/api/v2/get_suites/" + projectId).getBody();

    JSONArray json;//w  w  w. j a v a 2s.com
    try {
        json = new JSONArray(body);
    } catch (JSONException e) {
        return new Suite[0];
    }

    Suite[] suites = new Suite[json.length()];
    for (int i = 0; i < json.length(); i++) {
        JSONObject o = json.getJSONObject(i);
        Suite s = new Suite();
        s.setName(o.getString("name"));
        s.setId(o.getInt("id"));
        suites[i] = s;
    }

    return suites;
}

From source file:org.jenkinsci.plugins.testrail.TestRailClient.java

public Case[] getCases(int projectId, int suiteId) throws IOException, ElementNotFoundException {
    // "/#{project_id}&suite_id=#{suite_id}#{section_string}"
    String body = httpGet("index.php?/api/v2/get_cases/" + projectId + "&suite_id=" + suiteId).getBody();
    JSONArray json = new JSONArray(body);

    Case[] cases = new Case[json.length()];
    for (int i = 0; i < json.length(); i++) {
        JSONObject o = json.getJSONObject(i);
        cases[i] = createCaseFromJson(o);
    }// ww w.j  a v  a2  s  . c om

    return cases;
}

From source file:org.jenkinsci.plugins.testrail.TestRailClient.java

public Section[] getSections(int projectId, int suiteId) throws IOException, ElementNotFoundException {
    String body = httpGet("index.php?/api/v2/get_sections/" + projectId + "&suite_id=" + suiteId).getBody();
    JSONArray json = new JSONArray(body);

    Section[] sects = new Section[json.length()];
    for (int i = 0; i < json.length(); i++) {
        JSONObject o = json.getJSONObject(i);
        sects[i] = createSectionFromJSON(o);
    }/*from   ww  w .j  a v  a  2s.  c  o m*/

    return sects;
}

From source file:org.jenkinsci.plugins.testrail.TestRailClient.java

public Milestone[] getMilestones(int projectId) throws IOException, ElementNotFoundException {
    String body = httpGet("index.php?/api/v2/get_milestones/" + projectId).getBody();
    JSONArray json;/*from  ww w  .  j a  v a2s  . com*/
    try {
        json = new JSONArray(body);
    } catch (JSONException e) {
        return new Milestone[0];
    }
    Milestone[] suites = new Milestone[json.length()];
    for (int i = 0; i < json.length(); i++) {
        JSONObject o = json.getJSONObject(i);
        Milestone s = new Milestone();
        s.setName(o.getString("name"));
        s.setId(String.valueOf(o.getInt("id")));
        suites[i] = s;
    }
    return suites;
}

From source file:de.joinout.criztovyl.tools.json.JSONFile.java

/**
 * 
 * @return the {@link JSONObject} represented by the given data.
 */
public JSONArray getJSONArray() {
    return new JSONArray(data);
}

From source file:com.ss.android.apker.volley.toolbox.JsonArrayRequest.java

@Override
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) {
    try {// www . j  av a  2  s  .c  o  m
        String jsonString = new String(response.data,
                HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));
        return Response.success(new JSONArray(jsonString), HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    } catch (JSONException je) {
        return Response.error(new ParseError(je));
    }
}

From source file:de.duenndns.ssl.MemorizingTrustManager.java

private void writeFingerprintsToCache(String domain, List<String> results, long expires) {
    File file = getPoshCacheFile(domain);
    file.getParentFile().mkdirs();//ww  w . ja v a  2s  .c  o  m
    try {
        file.createNewFile();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("expires", expires);
        jsonObject.put("fingerprints", new JSONArray(results));
        FileOutputStream outputStream = new FileOutputStream(file);
        outputStream.write(jsonObject.toString().getBytes());
        outputStream.flush();
        outputStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:nl.hnogames.domoticzapi.Parsers.CameraParser.java

@Override
public void parseResult(String result) {
    try {/*  w  w  w. j  a  v a2  s . c o m*/
        JSONArray jsonArray = new JSONArray(result);
        ArrayList<CameraInfo> mCameras = new ArrayList<>();
        if (jsonArray.length() > 0) {
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject row = jsonArray.getJSONObject(i);
                CameraInfo cameraInfo = new CameraInfo(row);
                cameraInfo.setSnapShotURL(this.domoticz.getSnapshotUrl(cameraInfo));
                if (cameraInfo.getEnabled())
                    mCameras.add(cameraInfo);
            }
        }
        receiver.OnReceiveCameras(mCameras);
    } catch (JSONException e) {
        Log.e(TAG, "CameraParser JSON exception");
        e.printStackTrace();
        receiver.onError(e);
    }
}