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

This code example shows how to use the following methods:get, size
		public PublishMessage deserialize(JsonElement element, Type arg1,
				JsonDeserializationContext context) throws JsonParseException {
 
			JsonArray array = element.getAsJsonArray();
 
			if ( MessageType.fromInteger(array.get(0).getAsInt()) != concreteMessageType)
				return null; 
 
			PublishMessage msg = new PublishMessage();
			msg.topicUri = array.get(1).getAsString();
			if ( ! ( array.get(2) instanceof JsonNull ) )
				msg.payload = array.get(2);
			if ( array.size() == 4 ) {
				if ( array.get(3) instanceof JsonPrimitive)
					msg.excludeMe = array.get(3).getAsBoolean();
				else 
					return null; // exclude and eligible are not supported yet 
			} 
			else if ( array.size() == 5 )
				return null; // exclude and eligible are not supported yet 

7
CodeRank
This code example shows how to use the following methods:get, size
    @Override 
    public Bbox deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
        Bbox bbox = new Bbox();
        if (json instanceof JsonArray) {
            JsonArray array = (JsonArray)json;
            if (array.size() != 4) {
                throw new JsonParseException("Bbox must be of format [minX,minY,maxX,maxY]");
            } 
            // TODO check validity of bbox 
            bbox.setMinx(array.get(0).getAsDouble());
            bbox.setMiny(array.get(1).getAsDouble());
            bbox.setMaxx(array.get(2).getAsDouble());
            bbox.setMaxy(array.get(3).getAsDouble());
        } else { 
            throw new JsonParseException("Bbox must be JSON array");
        } 
        return bbox;
    } 
 
} 
6
CodeRank
This code example shows how to use the following methods:add
 
	public static class Serializer implements JsonSerializer<CallResultMessage> {
		@Override 
		public JsonElement serialize(CallResultMessage msg, Type arg1,
				JsonSerializationContext context) {
			JsonArray array = new JsonArray();
			array.add(context.serialize(msg.getType().getCode()));
			array.add(context.serialize(msg.callId));
			array.add(msg.payload.getGsonElement());
			return array;
		} 
	} 
 
	public static class Deserializer implements JsonDeserializer<CallResultMessage> {
		@Override 
		public CallResultMessage deserialize(JsonElement element, Type arg1,
				JsonDeserializationContext context) throws JsonParseException {
 
			JsonArray array = element.getAsJsonArray();
			 
6
CodeRank
This code example shows how to use the following methods:add, toString
				json.toString());
	} 
 
	@Test 
	public void testJsonArray() { 
		JsonArray jsons = new JsonArray();
		JsonObject json = new JsonObject();
		json.addProperty("name", "name1");
		json.addProperty("age", 1);
		jsons.add(json);
 
		json = new JsonObject();
		json.addProperty("name", "name2");
		json.addProperty("age", 2);
		jsons.add(json);
		// System.out.println(jsons.toString()); 
		Assert.assertEquals(
				"[{\"name\":\"name1\",\"age\":1},{\"name\":\"name2\",\"age\":2}]", 
				jsons.toString());
	} 

6
CodeRank
This code example shows how to use the following methods:get, size
    throws JsonParseException 
  { 
    Operation operation = null;
    if( json instanceof JsonArray ) {
      JsonArray opArray = ( JsonArray )json;
      String action = opArray.get( 0 ).getAsString();
      operation = createOperationFromJsonArray( action, opArray, context );
    } 
    return operation;
  } 
 
  private Operation createOperationFromJsonArray( String action,
                                                  JsonArray opArray,
                                                  JsonDeserializationContext context )
  { 
    Operation result = null;
    if( CreateOperation.ACTION.equals( action ) ) {
      result = createCreateOperation( opArray, context );
    } else if( SetOperation.ACTION.equals( action ) ) {
      result = createSetOperation( opArray, context );

6
CodeRank
This code example shows how to use the following methods:size
			ctx = context;
		} 
		 
		@Override 
		public int getCount() { 
			return users.size();
		} 
 
		@Override 
		public Object getItem(int pos) {
			try { 
				return users.get(pos);
			} catch (Exception e) {
				e.printStackTrace();
			} 
			return null; 
		} 
 
		@Override 
		public long getItemId(int pos) {
6
CodeRank
This code example shows how to use the following methods:add
 
	public static final JsonPrimitive IDENTIFIER = new JsonPrimitive("completed2");
 
	@Override 
	public JsonObject toJson() {
		JsonArray ret = new JsonArray();
		ret.add(IDENTIFIER);
		ret.add(new JsonPrimitive(this.getId()));
		return Reference.wrapAsReference(ret);
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:get, size
    @Override 
    public Center deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
        Center center = new Center();
        if (json instanceof JsonArray) {
            JsonArray array = (JsonArray)json;
            if (array.size() != 2) {
                throw new JsonParseException("Center must be of format [x,y]");
            } 
            // TODO check validity of bbox 
            center.setX(array.get(0).getAsDouble());
            center.setY(array.get(1).getAsDouble());
        } else { 
            throw new JsonParseException("Center must be JSON array");
        } 
        return center;
    } 
 
} 
6
CodeRank
This code example shows how to use the following methods:add
		return true; 
	} 
 
	public static final JsonPrimitive IDENTIFIER = new JsonPrimitive("val");
	public JsonObject toJson() {
		JsonArray ret = new JsonArray();
		ret.add(IDENTIFIER);
		ret.add(new JsonPrimitive(this.getId()));
		ret.add(new JsonPrimitive(new String(this.value)));
		return Reference.wrapAsReference(ret);
	} 
	 
} 
6
CodeRank
This code example shows how to use the following methods:add
	} 
 
	public static JsonPrimitive IDENTIFIER = new JsonPrimitive("f2");
	@Override 
	public JsonObject toJson() {
		JsonArray ret = new JsonArray();
		ret.add(IDENTIFIER);
		ret.add(new JsonPrimitive(this.getId()));
		return Reference.wrapAsReference(ret);
	} 
	 
	public String toString() {
		return "FutureReference(" + this.getId() + ")";
	} 
	 
	 
 
	 
} 
6
CodeRank
See Code Examples for Android JsonArray Methods: