Android JsonObject - 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 JsonObject class.

This code example shows how to use the following methods:addProperty
        helper.addAdditionalScript(function.toString());
    } 
 
    @Test 
    public void testResult() { 
        JsonObject data = new JsonObject();
        data.addProperty("title", "My name is");
        data.addProperty("x", "Bond,");
        data.addProperty("y", "James Bond");
 
        String template = Utils.readFile("src/main/webapp/template/dot/dummy-template-6.html");
        TestResult result = helper.doTemplateAsResult(template, data);
        assertEquals("Test", result.content("h1"));
        assertEquals("Test Test", result.content(".a"));
        assertEquals("Test", result.content(".a a"));
    } 
} 
6
CodeRank
This code example shows how to use the following methods:get, has
		return type;
	} 
 
	public boolean highlight() { 
		boolean highlight = false;
		if(o.has("highlight"))
			highlight = o.get("highlight").getAsBoolean();
		return highlight;
	} 
	 
	public boolean has(String name) {
		return o.has(name) && !o.get(name).isJsonNull();
	} 
	 
	public boolean getBoolean(String name) {
		if(!o.has(name) || o.get(name).isJsonNull())
			return false; 
		return o.get(name).getAsBoolean();
	} 
	 
6
CodeRank
This code example shows how to use the following methods:toString, addProperty
 
	 
	@Override 
	public String process(Map<String, String[]> params, String content)
			throws Exception, RestfulException { 
		JsonObject jsonReturn = new JsonObject();
		JSONObject json = null;
		try { 
			json = new JSONObject(content);
		} catch (Exception e) {
		} 
		 
		String userName = "0938365140";
		String password = "tamvominh";
		String toPhone = getParameterWithThrow("toPhone", params, json);
		String message = getParameterWithThrow("message", params, json);
 
		if(userName!=null && password!=null && toPhone!=null && message!=null)
		{ 
			if (SendSMSService.sendSms(userName, password, toPhone, message))

6
CodeRank
This code example shows how to use the following methods:add
  /** 
   * Static implementation-independent GSON serializer. Call this from 
   * {@link #toGson} to avoid subclassing issues with inner message types. 
   */ 
  public static JsonElement toGsonHelper(RobotSearchDigest message, RawStringData raw, Gson gson) {
    JsonObject json = new JsonObject();
    json.add("1", new JsonPrimitive(message.getWaveId()));
    { 
      JsonArray array = new JsonArray();
      for (int i = 0; i < message.getParticipantSize(); i++) {
        array.add(new JsonPrimitive(message.getParticipant(i)));
      } 
      json.add("2", array);
    } 
    json.add("3", new JsonPrimitive(message.getTitle()));
    json.add("4", new JsonPrimitive(message.getSnippet()));
    json.add("5", GsonUtil.toJson(message.getLastModifiedMillis()));
    json.add("6", new JsonPrimitive(message.getBlipCount()));
    json.add("7", new JsonPrimitive(message.getUnreadBlipCount()));
    return json;

6
CodeRank
This code example shows how to use the following methods:getAsJsonArray, getAsJsonObject, getAsJsonPrimitive
 
    private JsonObject getJsonObjectOrNull(JsonObject object, String index) {
        if (object == null)
            return null; 
        else 
            return object.getAsJsonObject(index);
    } 
 
    private JsonArray getJsonArrayOrNull(JsonObject object, String index) {
        if (object == null)
            return null; 
        else 
            return object.getAsJsonArray(index);
    } 
 
    private double getJsonDoubleOrNull(JsonObject object, String index) {
        if (object == null)
            return 0; 
        else 
            return object.getAsJsonPrimitive(index).getAsDouble();

6
CodeRank
This code example shows how to use the following methods:addProperty
	      
	      
	 
	  SimpleDateFormat daformat=new SimpleDateFormat("dd MMMM yyyy");
	  String date=daformat.format(Date);
	  JsonObject object=new JsonObject();
	  object.addProperty("txn_id", txnId);
	  object.addProperty("dateFormat","dd MMMM yyyy");
	  object.addProperty("locale","en");
	  object.addProperty("paymentDate",date);
	  object.addProperty("amountPaid",amount);
	  object.addProperty("isChequeSelected","no");
	  object.addProperty("receiptNo","1234");
	  object.addProperty("paypalemail", payerEmail);
	  object.addProperty("remarks",payerEmail);
	  object.addProperty("paymentCode",27);
	   
	  final CommandWrapper commandRequest = new CommandWrapperBuilder().createPaypal(payerEmail).withJson(object.toString()).build();
	  final CommandProcessingResult result1 = this.writePlatformService.logCommandSource(commandRequest);
	  return this.toApiJsonSerializer.serialize(result1); 
6
CodeRank
This code example shows how to use the following methods:addProperty
 
import java.lang.reflect.Type; 
 
public class ZoneTagSerializer implements JsonSerializer<ZoneTag> {
    public JsonElement serialize(ZoneTag zoneTag, Type type, JsonSerializationContext jsonSerializationContext) {
        JsonObject obj = new JsonObject();
        obj.addProperty("serial", zoneTag.getSerial());
        obj.addProperty("description", zoneTag.getDescription());
        return obj;
    } 
} 
6
CodeRank
This code example shows how to use the following methods:toString, addProperty
		try { 
			json = new JSONObject(content);
		} catch (Exception e) {
		} 
		 
		JsonObject jsonReturn = new JsonObject();
 
		ServiceResult<Void> result = dbNotification.deletAllNotifications();
		if (result.isOK()) {
			jsonReturn.addProperty("errCode", 0);
			jsonReturn.addProperty("message", result.getMessage());
		} else { 
			jsonReturn.addProperty("errCode", 1);
			jsonReturn.addProperty("message", result.getMessage());
		} 
		return jsonReturn.toString();
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:toString, add, addProperty
		} 
		 
		String query = getParameterWithThrow("q", params, json);
		query = UtilsFunction.removeViSign(query);
 
		JsonObject jsonReturn = new JsonObject();
		ServiceResult<List<Page>> result = db.searchPageLike(query);
		if (result.isOK()) {
			jsonReturn.addProperty("errCode", 0);
			jsonReturn.addProperty("message", result.getMessage());
			 
			jsonReturn.add("pages", Global.gsonWithDate.toJsonTree(result.getResult()));
		} else { 
			jsonReturn.addProperty("errCode", 1);
			jsonReturn.addProperty("message", result.getMessage());
		} 
		return jsonReturn.toString();
	} 
 
} 

6
CodeRank
This code example shows how to use the following methods:toString, add, addProperty
			q = getParameter("q", params, json);
			q = UtilsFunction.removeViSign(q);
		} catch (Exception e) {
		} 
 
		JsonObject jsonReturn = new JsonObject();
 
		ServiceResult<List<Product>> result = db.getListProductFromUsername(username, q, limit);
		if (result.isOK()) {
			jsonReturn.addProperty("errCode", 0);
			jsonReturn.addProperty("message", result.getMessage());
			 
			jsonReturn.add("products", Global.gsonWithDate.toJsonTree(result.getResult()));
		} else { 
			jsonReturn.addProperty("errCode", 1);
			jsonReturn.addProperty("message", result.getMessage());
		} 
		return jsonReturn.toString();
	} 
 

6
CodeRank

Related Android JsonObject Questions & Answers:

See Code Examples for Android JsonObject Methods: