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:com.mobeelizer.java.connection.MobeelizerConnectionServiceImpl.java

@Override
public MobeelizerOperationStatus<List<MobeelizerUser>> getUsers() {
    try {/*from w  ww  .  j  av  a  2 s.  c o  m*/
        MobeelizerOperationStatus<String> response = executeGetAndGetContent("/client/user/list");
        if (response.getError() != null) {
            return new MobeelizerOperationStatus<List<MobeelizerUser>>(response.getError());
        }

        JSONArray json = new JSONArray(response.getContent());

        List<MobeelizerUser> users = new ArrayList<MobeelizerUser>(json.length());

        for (int i = 0; i < json.length(); i++) {
            users.add(jsonObjectToUser(json.getJSONObject(i)));
        }

        return new MobeelizerOperationStatus<List<MobeelizerUser>>(users);
    } catch (JSONException e) {
        return new MobeelizerOperationStatus<List<MobeelizerUser>>(MobeelizerOperationErrorImpl.exception(e));
    }
}

From source file:com.mobeelizer.java.connection.MobeelizerConnectionServiceImpl.java

@Override
public MobeelizerOperationError sendRemoteNotification(final String device, final String group,
        final List<String> users, final Map<String, String> notification) {
    try {/*from  ww w  .  ja va2  s.c  o  m*/
        JSONObject object = new JSONObject();
        StringBuilder logBuilder = new StringBuilder();
        logBuilder.append("try to send remote notification ").append(notification).append(" to");
        if (device != null) {
            object.put("device", device);
            logBuilder.append(" device: ").append(device);
        }
        if (group != null) {
            object.put("group", group);
            logBuilder.append(" group: ").append(group);
        }
        if (users != null) {
            object.put("users", new JSONArray(users));
            logBuilder.append(" users: ").append(users);
        }
        if (device == null && group == null && users == null) {
            logBuilder.append(" everyone");
        }
        object.put("notification", new JSONObject(notification));
        delegate.logInfo(logBuilder.toString());
        return executePostAndGetContent("/push", object).getError();
    } catch (JSONException e) {
        return MobeelizerOperationErrorImpl.other(e.getMessage());
    }
}

From source file:org.indigo.cdmi.backend.radosgw.JsonUtils.java

/**
 * Converts JSON object, from the file pointed by path parameter, to JSONArrsy. 
 * /*from w  w  w  .  j av a2 s.  com*/
 * @param path Path to UTF-8 encoded file with JSON (exactly, with JSON array).
 * 
 * @return JSONArray created from file pointed by path parameter.
 */
public static JSONArray createJsonArrayFromFile(String path) {

    String jsonArrayAsString = fileToString(path);

    JSONArray rv = new JSONArray(jsonArrayAsString);

    return rv;

}

From source file:fr.simon.marquis.secretcodes.util.Utils.java

public static ArrayList<SecretCode> getSecretCodes(Context ctx) {
    ArrayList<SecretCode> res = new ArrayList<SecretCode>();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    try {//from  w ww.  j  av a  2s  .c o m
        JSONArray array = new JSONArray(prefs.getString(KEY_SECRET_CODES, ""));
        for (int i = 0; i < array.length(); i++) {
            SecretCode code = SecretCode.fromJSON(array.optJSONObject(i));
            if (code != null) {
                res.add(code);
            }
        }
        return res;
    } catch (JSONException e) {
        return res;
    }
}