Android JSONStringer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android JSONStringer class.

This code example shows how to use the following methods:endObject, key, object, toString, value
	private void log(String method) {
		log(method, null, null);
	} 
	private void log(String method, String extraKey, Object extraValue) {
		try { 
			JSONStringer js = new JSONStringer();
			js.object();
			js.key("method");
			js.value(method);
			if (extraKey!=null) {
				js.key(extraKey);
				js.value(extraValue);
			} 
			js.endObject();
			LoggingUtils.log(LOGTYPE_APPLICATION, js.toString());
		} 
		catch (Exception e) {
			Log.e(TAG,"log("+method+","+extraKey+","+extraValue+")", e);
		} 
	} 
6
CodeRank
This code example shows how to use the following methods:endObject, object
		} 
    } 
 
    public void WriteJsonObject(JSONStringer writer) throws JSONException
    { 
        writer.object();
        WriteJson(writer);
        writer.endObject();
    } 
 
    public static String WriteJson(ICanJson doc)
    { 
        JSONStringer jsonWriter = new JSONStringer();
         
        try { 
			jsonWriter.object();
			doc.WriteJson(jsonWriter);
			jsonWriter.endObject();
		} catch (JSONException e) {
			// TODO Auto-generated catch block 
6
CodeRank
This code example shows how to use the following methods:array, endArray, object, toString, value
	 
	//logging a call 
    private void logCall(Cursor mCallCursor) throws JSONException, RemoteException, UnsupportedEncodingException 
    { 
    	int i;
		JSONStringer data = new JSONStringer();
        data.object(); //json object to store the call
         
        data.key("number");
        i = mCallCursor.getColumnIndex(Calls.NUMBER);
        String number = mCallCursor.getString(i);
        data.value(number);
         
        data.key("name");
        i = mCallCursor.getColumnIndex(Calls.CACHED_NAME);
        data.value( mCallCursor.getString(i) );
         
        data.key("numberType");
        i = mCallCursor.getColumnIndex(Calls.CACHED_NUMBER_TYPE);
        int numberType = mCallCursor.getInt(i);

6
CodeRank
This code example shows how to use the following methods:endObject, object, toString
    public String getGameId() {
        return game.getId();
    } 
 
    private String generateStateMessage() {
        JSONStringer stringer = new JSONStringer();
        stringer.object();
        game.writeOutJsonObject(stringer, true);
        stringer.endObject();
 
        return stringer.toString();
    } 
 
    @Override 
    public String path() {
        return path;
    } 
 
    @Override 
    public void onOpen(WebSocket conn, ClientHandshake handshake) {
6
CodeRank
This code example shows how to use the following methods:toString
                } else { 
                    result = jsonObject.toString();
                } 
            } else if (this.jsonValue instanceof JSONStringer) {
                JSONStringer jsonStringer = (JSONStringer) this.jsonValue;
                result = jsonStringer.toString();
            } else if (this.jsonValue instanceof JSONTokener) {
                JSONTokener jsonTokener = (JSONTokener) this.jsonValue;
                result = jsonTokener.toString();
            } 
        } else if (this.jsonRepresentation != null) {
            try { 
                result = this.jsonRepresentation.getText();
            } catch (IOException e) {
                // [ifndef android] instruction 
                throw new JSONException(e);
                // [ifdef android] instruction uncomment 
                // throw new JSONException(e.getMessage()); 
            } 
        } 
6
CodeRank
This code example shows how to use the following methods:endObject, key, object, toString
        // this abstract base class gets here if the children verify local members 
        return true; 
    } 
 
    public String toJSONString() {
        JSONStringer stringer = new JSONStringer();
        try { 
        stringer.object();
        toJSONString(stringer);
        stringer.endObject();
        } catch (JSONException e) {
            e.printStackTrace();
            return null; 
        } 
        return stringer.toString();
    } 
 
    public void toJSONString(JSONStringer stringer) throws JSONException {
        stringer.key(Members.TYPE.name()).value(m_type.toString());
        stringer.key(Members.VALUE_TYPE.name()).value(m_valueType == null ? null : m_valueType.name());

5
CodeRank
This code example shows how to use the following methods:endObject, key, object
     *             When JSON output fails. 
     */ 
    private void deviceInfo(final JSONStringer json, final Info info)
        throws JSONException 
    { 
        json.object();
        json.key("name").value(info.getName());
        json.key("description").value(info.getDescription());
        json.key("vendor").value(info.getVendor());
        json.key("version").value(info.getVersion());
        json.endObject();
    } 
 
    /** 
     * Returns an array of information objects representing the set of all MIDI 
     * devices available on the system. 
     * 
     * @return The array of information objects about all available MIDI 
     *         devices. 
     * @throws JSONException 
5
CodeRank
This code example shows how to use the following methods:array, endArray, object
						addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.TYPE));
	    	} 
	     	addrCur.close();
        } 
         
        data.array();
    	data.object()
    			.key("displayName").value(displayName)
    			.key("givenName").value(givenName)
    			.key("familyName").value(familyName)
    			.key("type").value(type)
    			.key("phoneNo").value(phoneNo)
    			.key("phoneType").value(phoneType)
    			.key("emailAddress").value(emailAddress)
    			.key("emailType").value(emailType)
    			.key("street").value(street)
    			.key("city").value(city)
    			.key("region").value(region)
    			.key("postalCode").value(postalCode)
    			.key("country").value(country)

5
CodeRank
This code example shows how to use the following methods:object, toString
		this.nome = nome;
		this.valor = valor;
	} 
	 
	public String toJson() throws JSONException {
		JSONStringer j = new JSONStringer();
		 
		j.object()
			.key("id").value(id)
			.key("id").value(id)
			.key("id").value(id)
		.endObject();
		 
		return j.toString();
	} 
	 
	public Long getId() {
		return id;
	} 
 
5
CodeRank
This code example shows how to use the following methods:object, toString
	public String toString() {
		return id + " - " + nome;
	} 
 
	public String toJSON() throws JSONException{
		JSONStringer j = new JSONStringer();
		j.object().key("id").value(id).
		key("nome").value(nome).
		key("telefone").value(telefone).
		key("endereco").value(endereco).
		key("foto").value(foto).
		key("nota").value(nota).endObject();
		return j.toString();
	} 
} 
5
CodeRank

Related Android JSONStringer Questions & Answers:

See Code Examples for Android JSONStringer Methods: