Example usage for org.json JSONObject getString

List of usage examples for org.json JSONObject getString

Introduction

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

Prototype

public String getString(String key) throws JSONException 

Source Link

Document

Get the string associated with a key.

Usage

From source file:ru.otdelit.astrid.opencrx.sync.OpencrxSyncProvider.java

/**
 * Puts a single label into the cache//from   w w  w. j a  v a  2  s .c  om
 * @param dashboardId
 * @param label
 * @throws JSONException
 */
private String putLabelIntoCache(JSONObject label) throws JSONException {

    String name = label.getString("name");
    String id = label.getString("id");

    labelMap.put(name, id);

    return id;
}

From source file:com.asd.littleprincesbeauty.data.Task.java

@Override
public void setContentByRemoteJSON(JSONObject js) {
    if (js != null) {
        try {/*from w ww .  ja v a 2 s . com*/
            // id
            if (js.has(GTaskStringUtils.GTASK_JSON_ID)) {
                setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID));
            }

            // last_modified
            if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) {
                setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED));
            }

            // name
            if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) {
                setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME));
            }

            // notes
            if (js.has(GTaskStringUtils.GTASK_JSON_NOTES)) {
                setNotes(js.getString(GTaskStringUtils.GTASK_JSON_NOTES));
            }

            // deleted
            if (js.has(GTaskStringUtils.GTASK_JSON_DELETED)) {
                setDeleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_DELETED));
            }

            // completed
            if (js.has(GTaskStringUtils.GTASK_JSON_COMPLETED)) {
                setCompleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_COMPLETED));
            }
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
            e.printStackTrace();
            throw new ActionFailureException("fail to get task content from jsonobject");
        }
    }
}

From source file:com.asd.littleprincesbeauty.data.Task.java

@Override
public void setContentByLocalJSON(JSONObject js) {
    if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE) || !js.has(GTaskStringUtils.META_HEAD_DATA)) {
        Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
    }/*from  ww w  .ja  va  2  s .c  o  m*/

    try {
        JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
        JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);

        if (note.getInt(NoteColumns.TYPE) != Notes.TYPE_NOTE) {
            Log.e(TAG, "invalid type");
            return;
        }

        for (int i = 0; i < dataArray.length(); i++) {
            JSONObject data = dataArray.getJSONObject(i);
            if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
                setName(data.getString(DataColumns.CONTENT));
                break;
            }
        }

    } catch (JSONException e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
    }
}

From source file:com.asd.littleprincesbeauty.data.Task.java

@Override
public JSONObject getLocalJSONFromContent() {
    String name = getName();//from  ww w  .j a  v a  2 s  .  c  o m
    try {
        if (mMetaInfo == null) {
            // new task created from web
            if (name == null) {
                Log.w(TAG, "the note seems to be an empty one");
                return null;
            }

            JSONObject js = new JSONObject();
            JSONObject note = new JSONObject();
            JSONArray dataArray = new JSONArray();
            JSONObject data = new JSONObject();
            data.put(DataColumns.CONTENT, name);
            dataArray.put(data);
            js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
            note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
            js.put(GTaskStringUtils.META_HEAD_NOTE, note);
            return js;
        } else {
            // synced task
            JSONObject note = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
            JSONArray dataArray = mMetaInfo.getJSONArray(GTaskStringUtils.META_HEAD_DATA);

            for (int i = 0; i < dataArray.length(); i++) {
                JSONObject data = dataArray.getJSONObject(i);
                if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
                    data.put(DataColumns.CONTENT, getName());
                    break;
                }
            }

            note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
            return mMetaInfo;
        }
    } catch (JSONException e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
        return null;
    }
}

From source file:cz.karry.vpnc.LunaService.java

@LunaServiceThread.PublicMethod
public void connectionInfo(final ServiceMessage msg) throws JSONException, LSException {
    JSONObject jsonObj = msg.getJSONPayload();
    if (!jsonObj.has("name")) {
        msg.respondError("1", "Improperly formatted request.");
        return;/*w w  w.  j  av a 2  s  .  c o m*/
    }

    String name = jsonObj.getString("name");

    JSONObject reply = new JSONObject();
    reply.put("name", name);
    VpnConnection conn = vpnConnections.get(name);
    ConnectionState state = VpnConnection.ConnectionState.INACTIVE;
    String log = "";

    if (conn != null) {
        state = conn.getConnectionState();
        log = conn.getLog();
        if (state == AbstractVpnConnection.ConnectionState.CONNECTED) {
            reply.put("localAddress", conn.getLocalAddress());
        }
    }

    try {
        reply.put("profileName", name);
        reply.put("state", state);
        reply.put("log", log);
        //tcpLogger.log("refresh info: "+reply.toString());
        msg.respond(reply.toString());
    } catch (LSException ex) {
        tcpLogger.log(ex.getMessage(), ex);
    } catch (JSONException ex) {
        tcpLogger.log(ex.getMessage(), ex);
    }
}

From source file:cz.karry.vpnc.LunaService.java

@LunaServiceThread.PublicMethod
public void listenOnChanges(final ServiceMessage msg) throws JSONException, LSException {
    JSONObject jsonObj = msg.getJSONPayload();
    if (!jsonObj.has("name")) {
        msg.respondError("1", "Improperly formatted request.");
        return;/* w  ww.  j a  v a 2s  .  c  om*/
    }
    String name = jsonObj.getString("name");

    VpnConnection conn = vpnConnections.get(name);
    if (conn != null) {
        tcpLogger.log("add listener for " + name);
        conn.addStateListener(new ConnectionStateListenerImpl(msg, conn, this.getNextListenerId()));
    }
}

From source file:cz.karry.vpnc.LunaService.java

@LunaServiceThread.PublicMethod
public void disconnectVpn(final ServiceMessage msg) throws JSONException, LSException {
    JSONObject jsonObj = msg.getJSONPayload();
    if (!jsonObj.has("name")) {
        msg.respondError("1", "Improperly formatted request. (" + jsonObj.toString() + ")");
        return;/*www  .  j av a 2s.c  o  m*/
    }

    String name = jsonObj.getString("name");
    VpnConnection conn = vpnConnections.get(name);
    if (conn == null) {
        msg.respondError("2", "Connection '" + name + "' is not registered.");
        return;
    }

    conn.addStateListener(new ConnectionStateListenerImpl(msg, conn, this.getNextListenerId()));
    conn.diconnect();
    //msg.respondTrue();
}

From source file:cz.karry.vpnc.LunaService.java

@LunaServiceThread.PublicMethod
public void connectVpn(final ServiceMessage msg) throws JSONException, LSException {
    JSONObject jsonObj = msg.getJSONPayload();

    tcpLogger.log("invoke connectVpn " + jsonObj.toString());

    if ((!jsonObj.has("type")) || (!jsonObj.has("name")) || (!jsonObj.has("display_name"))
            || (!jsonObj.has("configuration"))) {
        msg.respondError("1", "Improperly formatted request. (" + jsonObj.toString() + ")");
        return;/*from ww w  .  ja  v a 2  s .c om*/
    }

    String type = jsonObj.getString("type");
    String name = jsonObj.getString("name");
    String displayName = jsonObj.getString("display_name");
    JSONObject configuration = jsonObj.getJSONObject("configuration");

    if (!name.matches("^[a-zA-Z]{1}[a-zA-Z0-9]*$")) {
        msg.respondError("2", "Bad session name format.");
        return;
    }

    if (type.toLowerCase().equals("pptp")) {
        String host = configuration.getString("host").replaceAll("\n", "\\\\n");

        String user = configuration.getString("pptp_user").replaceAll("\n", "\\\\n");
        String pass = configuration.getString("pptp_password").replaceAll("\n", "\\\\n");
        String mppe = configuration.getString("pptp_mppe").replaceAll("\n", "\\\\n");
        String mppe_stateful = configuration.getString("pptp_mppe_stateful").replaceAll("\n", "\\\\n");
        connectPptpVpn(msg, name, displayName, host, user, pass, mppe, mppe_stateful);
        return;
    } else if (type.toLowerCase().equals("openvpn")) {
        String host = configuration.getString("host").replaceAll("\n", "\\\\n");

        String topology = configuration.getString("openvpn_topology");
        String protocol = configuration.getString("openvpn_protocol");
        String cipher = configuration.getString("openvpn_cipher");
        this.connectOpenVPN(msg, name, displayName, host, topology, protocol, cipher);
        return;
    } else if (type.toLowerCase().equals("cisco")) {
        String host = configuration.getString("host").replaceAll("\n", "\\\\n");

        String userid = configuration.getString("cisco_userid").replaceAll("\n", "\\\\n");
        String userpass = configuration.getString("cisco_userpass").replaceAll("\n", "\\\\n");
        String groupid = configuration.getString("cisco_groupid").replaceAll("\n", "\\\\n");
        String grouppass = configuration.getString("cisco_grouppass").replaceAll("\n", "\\\\n");
        String userpasstype = configuration.getString("cisco_userpasstype");
        String grouppasstype = configuration.getString("cisco_grouppasstype");
        String domain = configuration.has("cisco_domain") && configuration.getString("cisco_domain") != null
                && configuration.getString("cisco_domain").trim().length() > 0
                        ? "Domain " + configuration.getString("cisco_domain")
                        : "";
        tcpLogger.log("use domain \"" + domain + "\"");
        this.connectCiscoVpn(msg, name, displayName, host, userid, userpass, userpasstype, groupid, grouppass,
                grouppasstype, domain);
        return;
    }

    msg.respondError("3", "Undefined vpn type (" + type + ").");
}

From source file:com.autburst.picture.server.PictureServer.java

public String[] getImageList(String id) throws Exception {
    HttpRequest request = new HttpRequest();
    String url = BASE_URL + "/" + id;

    Log.d(TAG, "getImageList - url: " + url);

    String response = request.get(url);

    if (response != null && !response.equals("null")) {
        //parse JSON
        JSONObject json = new JSONObject(response);

        JSONArray jsonArray = null;/*from w  w w  .j  a va 2  s .  co m*/
        String singleFileName = null;
        try {
            jsonArray = json.getJSONArray("files");
        } catch (JSONException e) {
            Log.e(TAG, "No JSONArray returned!");

            //get single filename
            singleFileName = json.getString("files");
        }

        if (jsonArray == null) {
            singleFileName = json.getString("files");
            Log.d(TAG, "getImageList - Server returned one file " + singleFileName);
            return new String[] { singleFileName };
        } else {
            String[] resultList = new String[jsonArray.length()];
            for (int i = 0; i < jsonArray.length(); i++) {
                resultList[i] = jsonArray.getString(i);
                Log.d(TAG, "getImageList - Server returned " + resultList[i]);
            }
            return resultList;
        }
    } else {
        Log.d(TAG, "getImageList - Server returned null images");
        return new String[0];
    }
}

From source file:com.iespuig.attendancemanager.StudentFetchr.java

public ArrayList<Student> fetchStudent(Classblock classBlock) {
    ArrayList<Student> items = new ArrayList<Student>();

    SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(context);
    String schoolName = SP.getString(("schoolName"), "");
    String urlServer = SP.getString("urlServer", "");

    Format formatter = new SimpleDateFormat("ddMMyyyy");

    try {/*from ww w .  ja  v a  2  s .  com*/
        String url = Uri.parse(urlServer).buildUpon().appendQueryParameter("action", ACTION_GET_STUDENTS)
                .appendQueryParameter("school", schoolName)
                .appendQueryParameter("login", User.getInstance().getLogin())
                .appendQueryParameter("password", User.getInstance().getPassword())
                .appendQueryParameter("idGroup", String.valueOf(classBlock.getIdGroup()))
                .appendQueryParameter("idClassBlock", String.valueOf(classBlock.getId()))
                .appendQueryParameter("date", formatter.format(classBlock.getDate())).build().toString();

        Log.i(TAG, "url: " + url);

        String data = AtmNet.getUrl(url);
        Log.i(TAG, "url: " + data);

        JSONObject jsonObject = new JSONObject(data);
        JSONArray jsonArray = new JSONArray(jsonObject.getString("data"));

        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject row = jsonArray.getJSONObject(i);

            Student item = new Student();

            item.setId(row.getInt("id"));
            item.setFullname(row.getString("fullname"));
            item.setName(row.getString("name"));
            item.setSurname1(row.getString("surname1"));
            item.setSurname2(row.getString("surname2"));
            item.setMissType(0);
            item.setNotMaterial(false);
            item.setNetworkTransit(false);

            if (row.has("misses")) {
                JSONArray misses = row.getJSONArray("misses");
                for (int j = 0; j < misses.length(); j++) {
                    int miss = misses.getInt(j);
                    if (miss > NOT_MISS && miss <= EXPULSION) {
                        item.setMissType(miss);
                    }
                    if (miss == NOT_MATERIAL)
                        item.setNotMaterial(true);
                }
            }

            items.add(item);
        }
    } catch (IOException ioe) {
        Log.e(TAG, "Failed to fetch items", ioe);

    } catch (JSONException je) {
        Log.e(TAG, "Failed to parse JSON", je);
    }
    return items;
}