Package org.json

Examples of org.json.JSONArray.opt()


        final JSONArray converted = json.getJSONObject(SerTokens.TOKEN_RESULT).getJSONArray(SerTokens.TOKEN_DATA);

        assertEquals(3, converted.length());

        assertEquals("x", converted.get(0));
        assertEquals(JSONObject.NULL, converted.opt(1));
        assertEquals("y", converted.get(2));
    }

    @Test
    public void serializeToJsonMap() throws Exception {
View Full Code Here


                }
                output.put( references.opt( idx ) );
            }
            for( int idx = 0; idx < output.length(); idx++ )
            {
                references.put( idx, output.opt( idx ) );
            }
        }
    }
}
View Full Code Here

    if (o instanceof JSONObject) {
      rewrite((JSONObject) o, scheme, hostname, port, contextPath);
    } else if (o instanceof JSONArray) {
      JSONArray a = (JSONArray) o;
      for (int i = 0; i < a.length(); i++) {
        Object v = a.opt(i);
        if (v instanceof URI) {
          try {
            a.put(i, unqualifyArrayValue(i, (URI) v, scheme, hostname, port));
          } catch (JSONException e) {
          }
View Full Code Here

            JSONArray jsonActual = (JSONArray)actual;
            if (jsonExpected.length() != jsonActual.length()) {
                return false;
            }
            for (int i = 0; i < jsonExpected.length(); ++i) {
                if (!isJSONEquals(jsonExpected.opt(i), jsonActual.opt(i))) {
                    return false;
                }
            }
            return true;
        }
View Full Code Here

      return json.toString();
    } else if (json instanceof JSONArray) {
      JSONArray jsonArray = (JSONArray) json;
      ImmutableList.Builder<Object> values = ImmutableList.builder();
      for (int i = 0, j = jsonArray.length(); i < j; ++i) {
        values.add(jsonToConfig(jsonArray.opt(i)));
      }
      return values.build();
    } else if (json instanceof JSONObject) {
      return jsonToMap((JSONObject) json);
    }
View Full Code Here

      return new DynamicConfigProperty(json.toString(), expressions, context);
    } else if (json instanceof JSONArray) {
      JSONArray jsonArray = (JSONArray) json;
      List<Object> values = new ArrayList<Object>(jsonArray.length());
      for (int i = 0, j = jsonArray.length(); i < j; ++i) {
        values.add(jsonToConfig(jsonArray.opt(i), expressions, context));
      }
      return Collections.unmodifiableList(values);
    } else if (json instanceof JSONObject) {
      return jsonToMap((JSONObject) json, expressions, context);
    }
View Full Code Here

  static private void applyIntegerAttributePatch(Object obj, int index, JSONObject patch, String patchKey) throws Exception {
    Object patchValue = patch.get(patchKey);

    if( obj instanceof JSONArray ){
      JSONArray jsonArr = (JSONArray)obj;
      Object currentValue = jsonArr.opt(index);
      if( null == currentValue ){
        // Clone
        if( patchValue instanceof JSONObject ) {
          JSONObject clone = JSONSupport.copyObject((JSONObject)patchValue);
          jsonArr.put(index, clone);
View Full Code Here

        Assert.assertEquals("string", json.optString(0));
        Assert.assertEquals(123, json.optInt(1));
        Assert.assertEquals(123.456, json.optDouble(2), 1e-15);
        Assert.assertEquals(true, json.optBoolean(3));
        Assert.assertEquals(false, json.optBoolean(4));
        Assert.assertEquals(null, json.opt(5));
    }

}
View Full Code Here

          JSONArray sortArray = json.optJSONArray(RequestConverter2.SORT);
          if (sortArray!=null && sortArray.length()>0){
            ArrayList<SortField> sortFieldList = new ArrayList<SortField>(sortArray.length());
            for (int i=0;i<sortArray.length();++i){
              Object obj = sortArray.opt(i);
              if(obj instanceof JSONObject){
                String field = (String) ((JSONObject)obj).keys().next();
                if (field == null || field.length() == 0)
                  continue;
                if (SORT_SCORE.equals(field) || SORT_RELEVANCE.equalsIgnoreCase(field))
View Full Code Here

      return new DynamicConfigProperty(json.toString(), expressions, context);
    } else if (json instanceof JSONArray) {
      JSONArray jsonArray = (JSONArray) json;
      List<Object> values = new ArrayList<Object>(jsonArray.length());
      for (int i = 0, j = jsonArray.length(); i < j; ++i) {
        values.add(jsonToConfig(jsonArray.opt(i), expressions, context));
      }
      return Collections.unmodifiableList(values);
    } else if (json instanceof JSONObject) {
      return jsonToMap((JSONObject) json, expressions, context);
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.