JSONArray get - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for JSONArray get method.

This code example shows how to use the following methods:get, length
      return new JSONArray("[" + value.substring(1, value.length() - 1) + "]");
    } else { 
      try { 
        // inferred parsing of literal array 
        // Attempt to parse as an array of literals 
        JSONArray parsedArray = new JSONArray("[" + value + "]");
        if (parsedArray.length() == 1) {
          // Not an array 
          return parsedArray.get(0);
        } 
        return parsedArray;
      } catch (JSONException je) {
        return value;
      } 
    } 
  } 
} 
7
CodeRank
This code example shows how to use the following methods:get
    assertEquals(false, JsonUtil.convertJsonItem("faLse"));
  } 
 
  public void testConvertNumber() throws JSONException { 
    String jsonInput = "[9.5,-9.5,9,-9,123456789101112,0xF]";
    JSONArray array = new JSONArray(jsonInput);
    assertEquals(9.5, JsonUtil.convertJsonItem(array.get(0)));
    assertEquals(-9.5, JsonUtil.convertJsonItem(array.get(1)));
    assertEquals(9, JsonUtil.convertJsonItem(array.get(2)));
    assertEquals(-9, JsonUtil.convertJsonItem(array.get(3)));
    assertEquals(123456789101112L, JsonUtil.convertJsonItem(array.get(4)));
    assertEquals(15, JsonUtil.convertJsonItem(array.get(5)));
  } 
} 
6
CodeRank
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
    } 
 
    @Override 
    public Object getItem(int position) {
        try { 
            return mArray.get(position);
        } catch (JSONException e) {
            throw new IllegalStateException(e);
        } 
//        throw new IllegalArgumentException("position " + position + " in a list of size " + mArray.length()); 
    } 
 
    @Override 
    public long getItemId(int position) {
        return position;
    } 
 
    @Override 
    public View getView(int position, View view, ViewGroup parent) {
        JSONObject item = (JSONObject) getItem(position);
6
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:get, getString, length
	public static List<PlacesInfo> parsePlaces(String responseString) throws RBParserException {
		ArrayList<PlacesInfo> results = new ArrayList<PlacesInfo>();
 
		try { 
			Log.d(LOGTAG, "Creating JSON Object");
			JSONArray jsonObjects = new JSONArray(responseString);
			 
			Log.d(LOGTAG, "ARRAY LENGTH: " + jsonObjects.length());
			for (int i = 0; i < jsonObjects.length(); i++) {
				PlacesInfo place = new PlacesInfo();
				 
				Log.d(LOGTAG, "JSONObject("+i+"): " + jsonObjects.get(i));
				JSONObject json = new JSONObject(jsonObjects.getString(i));
				 
				//{"PlaceID":6996,"PlaceName":"Lush Wine and Spirits","PlaceType":"3","Address":"1257 S. Halsted St.", 
				//"City":"Chicago","StateID":14,"CountryID":213,"PostalCode":"60607","PhoneNumber":"738-1900","AvgRating":33.5, 
				//"PhoneAC":"312","Latitude":41.865794,"Longitude":-87.646683,"Distance":1.368293} 
				place.setPlaceID(json.getString("PlaceID"));
				place.setPlaceName(json.getString("PlaceName"));
				place.setPlaceType(json.getString("PlaceType"));
6
CodeRank
This code example shows how to use the following methods:get, length
    } 
 
	public static Object makeList(Property property, JSONArray jsonArray) {
        Property componentProperty = property.getComponentProperty();
 
        int size = jsonArray.length();
 
        List<Object> list = new ArrayList<Object>(size);
 
        try { 
            for (int i = 0; i < size; i++) {
                Object value = jsonArray.get(i);
                list.add(makeSettableValue(componentProperty, value));
            } 
        } catch (JSONException je) {
            throw new RuntimeException(je);
        } 
 
        return list;
    } 
6
CodeRank
This code example shows how to use the following methods:get, length
            return sourceResponses;
        } 
        if(tikaResponse ==null)
            return sourceResponses;
        try { 
            JSONArray sourceArray = new JSONArray(tikaResponse);
            for (int i = 0; i < sourceArray.length(); i++) {
                JSONObject object = (JSONObject) sourceArray.get(i);
                String id = object.getString("id");
                String accountType = object.getString("accountType");
                String name = object.getString("name");
                String cat = object.getString("cat");
 
                String imageURL = "";
                if (object.has("image_url"))
                    object.getString("image_url");
                String desc = object.getString("desc");
                String contentURL = "";
                if (object.has("content_url"))
                    contentURL = object.getString("content_url");
6
CodeRank
This code example shows how to use the following methods:get
    } 
 
 
    // Pass through the basics to the base args. 
    public Object get(int index) throws JSONException {
        return baseArgs.get(index);
    } 
 
    public boolean getBoolean(int index) throws JSONException {
        return baseArgs.getBoolean(index);
    } 
 
    public double getDouble(int index) throws JSONException {
        return baseArgs.getDouble(index);
    } 
 
    public int getInt(int index) throws JSONException {
        return baseArgs.getInt(index);
    } 
 
6
CodeRank
This code example shows how to use the following methods:get, length
            return sourceResponses;
        } 
        if(tikaResponse ==null)
            return sourceResponses;
        try { 
            JSONArray sourceArray = new JSONArray(tikaResponse);
            for (int i = 0; i < sourceArray.length(); i++) {
                JSONObject object = (JSONObject) sourceArray.get(i);
                String id = object.getString("id");
                String accountType = object.getString("accountType");
                String name = object.getString("name");
                String cat = object.getString("cat");
 
                String imageURL = "";
                if (object.has("image_url"))
                    object.getString("image_url");
                String desc = object.getString("desc");
                String contentURL = "";
                if (object.has("content_url"))
                    contentURL = object.getString("content_url");
6
CodeRank

Related JSONArray get Questions & Answers:

get Method Overview
Returns the value at index.
See Code Examples for other Android JSONArray Methods: