当前位置: 首页>>代码示例>>Java>>正文


Java JSONArray.isNull方法代码示例

本文整理汇总了Java中org.json.JSONArray.isNull方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.isNull方法的具体用法?Java JSONArray.isNull怎么用?Java JSONArray.isNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.json.JSONArray的用法示例。


在下文中一共展示了JSONArray.isNull方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mergeJSONArray

import org.json.JSONArray; //导入方法依赖的package包/类
/**
 * Merge two JSON arrays
 *
 * @param target On merge conflicts this object loses
 * @param source On merge conflicts this object wins
 * @return the merged json array
 * @throws JSONException the json exception
 */
private static JSONArray mergeJSONArray(final JSONArray target, final JSONArray source) throws JSONException {
    final JSONArray newArray = padJSONArray(target, source.length());

    for (Integer i = 0; i < source.length(); i++) {
        if (!source.isNull(i)) {
            Object newValue = source.get(i);

            if (!newArray.isNull(i)) {
                newValue = merge(newArray.get(i), source.get(i));
            }

            newArray.put(i, newValue);
        }
    }

    return newArray;
}
 
开发者ID:mhaddon,项目名称:Sound.je,代码行数:26,代码来源:JSONUtil.java

示例2: getMetricFromFacet

import org.json.JSONArray; //导入方法依赖的package包/类
private Metric getMetricFromFacet(JSONObject jFacet) {

    // Lookup the app
    JSONArray jName = jFacet.getJSONArray("name");

    // Make sure both facets came back correctly
    if (!jName.isNull(0) && !jName.isNull(1)) {

      // Lookup this app from our config
      String sAppName = jName.getString(0);
      Application app = copierConfig.getApplication(sAppName);
      String sMetricName = jName.getString(1);
      return getMetricFromApp(app, sMetricName);
    }

    return null;
  }
 
开发者ID:kenahrens,项目名称:newrelic-api-client-java,代码行数:18,代码来源:ExtractInsights.java

示例3: readCollectionField

import org.json.JSONArray; //导入方法依赖的package包/类
/**
 * Read data from the given JSONArray and populate the given Collection
 * 
 * @param json_array
 * @param catalog_db
 * @param collection
 * @param inner_classes
 * @throws Exception
 */
@SuppressWarnings("unchecked")
protected static void readCollectionField(final JSONArray json_array, final Database catalog_db, final Collection collection, final Stack<Class<?>> inner_classes) throws Exception {
    // We need to figure out what the inner type of the collection is
    // If it's a Collection or a Map, then we need to instantiate it before
    // we can call readFieldValue() again for it.
    Class<?> inner_class = inner_classes.pop();
    Collection<Class<?>> inner_interfaces = ClassUtil.getInterfaces(inner_class);
    final Stack<Class<?>> next_inner_classes = new Stack<Class<?>>();
    
    for (int i = 0, cnt = json_array.length(); i < cnt; i++) {
        if (i > 0) next_inner_classes.clear();
        next_inner_classes.addAll(inner_classes);
        assert (next_inner_classes.equals(inner_classes));
        Object value = null;

        // Null
        if (json_array.isNull(i)) {
            value = null;
            // Lists
        } else if (inner_interfaces.contains(List.class)) {
            value = new ArrayList<Object>();
            readCollectionField(json_array.getJSONArray(i), catalog_db, (Collection<?>) value, next_inner_classes);
            // Sets
        } else if (inner_interfaces.contains(Set.class)) {
            value = new HashSet<Object>();
            readCollectionField(json_array.getJSONArray(i), catalog_db, (Collection<?>) value, next_inner_classes);
            // Maps
        } else if (inner_interfaces.contains(Map.class)) {
            value = new HashMap<Object, Object>();
            readMapField(json_array.getJSONObject(i), catalog_db, (Map<Object, Object>) value, next_inner_classes);
            // Values
        } else {
            String json_string = json_array.getString(i);
            value = JSONUtil.getPrimitiveValue(json_string, inner_class, catalog_db);
        }
        collection.add(value);
    } // FOR
    return;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:49,代码来源:JSONUtil.java

示例4: loadFromJSONObject

import org.json.JSONArray; //导入方法依赖的package包/类
@Override
protected void loadFromJSONObject(JSONObject obj, Database db) throws JSONException {
    super.loadFromJSONObject(obj, db);
    JSONArray valuesArray = obj.getJSONArray(Members.VALUES.name());
    for (int ii = 0; ii < valuesArray.length(); ii++) {
        if (valuesArray.isNull(ii)) {
            m_values.add(null);
        } else {
            m_values.add( AbstractExpression.fromJSONObject(valuesArray.getJSONObject(ii), db));
        }
    }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:13,代码来源:InComparisonExpression.java

示例5: getLastAggregatedTime

import org.json.JSONArray; //导入方法依赖的package包/类
/**
 * Get the last aggregated time for each report based on the report type
 * @param reportType Report type
 * @return
 */
public Date getLastAggregatedTime(String reportType){
  if (StringUtils.isBlank(reportType)) {
    xLogger.warn(
        "Invalid report type received {0}", reportType);
    throw new BadRequestException("Invalid request");
  }
  String aggregationRunTimeKey = ReportsUtil.getAggregationReportType(reportType);
  if (StringUtils.isBlank(aggregationRunTimeKey)) {
    xLogger.warn(
        "report type not configured {0}", reportType);
    throw new BadRequestException("Invalid request");
  }
  //Set the filters
  QueryRequestModel model = new QueryRequestModel();
  model.filters = new HashMap<>(1);
  model.filters.put(QueryHelper.TOKEN_RUN_TIME, aggregationRunTimeKey);
  model.queryId = QueryHelper.QUERY_LAST_RUN_TIME;
  //Request callisto for data
  ExternalServiceClient externalServiceClient = ExternalServiceClient.getNewInstance();
  Response response = externalServiceClient.postRequest(model);
  //parse response
  if (response != null) {
    JSONObject jsonObject = new JSONObject(response.readEntity(String.class));
    JSONArray rows = jsonObject.has(ReportsConstants.ROWS) ? jsonObject.getJSONArray
        (ReportsConstants.ROWS) : null;
    if (rows != null && !rows.isNull(0) && rows.getJSONArray(0).get(0) != null) {
      try {
        return LocalDateUtil
            .parseCustom((String) rows.getJSONArray(0).get(0), Constants.ANALYTICS_DATE_FORMAT,
                null);
      } catch (ParseException e) {
        xLogger.warn("Exception parsing date", e);
      }
    }
  }
  return null;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:43,代码来源:ReportPluginService.java

示例6: parseArrayOfDatabaseEntities

import org.json.JSONArray; //导入方法依赖的package包/类
/**
 * Saves and associate these database entities to this object
 *
 * @param value database entities to process
 * @param type  type of the database entities
 * @return new list of database entities
 * @throws JSONException the exception
 */
private List<Object> parseArrayOfDatabaseEntities(final JSONArray value, final Class type) throws JSONException {
    final List<Object> elements = new ArrayList<>();

    for (Integer i = 0; i < value.length(); i++) {
        if (!value.isNull(i)) {
            final JSONObject data = (JSONObject) value.get(i);
            elements.add(parseBaseEntity(data, type));
        }
    }
    return elements;
}
 
开发者ID:mhaddon,项目名称:Sound.je,代码行数:20,代码来源:FormParse.java

示例7: call

import org.json.JSONArray; //导入方法依赖的package包/类
public String call(WebView webView, String jsonStr) {
	if (!TextUtils.isEmpty(jsonStr)) {
		try {
			JSONObject callJson = new JSONObject(jsonStr);
			String methodName = callJson.getString("method");
			JSONArray argsTypes = callJson.getJSONArray("types");
			JSONArray argsVals = callJson.getJSONArray("args");
			String sign = methodName;
			int len = argsTypes.length();
			Object[] values = new Object[len + 1];
			int numIndex = 0;
			String currType;

			values[0] = webView;

			for (int k = 0; k < len; k++) {
				currType = argsTypes.optString(k);
				if ("string".equals(currType)) {
					sign += "_S";
					values[k + 1] = argsVals.isNull(k) ? null : argsVals.getString(k);
				} else if ("number".equals(currType)) {
					sign += "_N";
					numIndex = numIndex * 10 + k + 1;
				} else if ("boolean".equals(currType)) {
					sign += "_B";
					values[k + 1] = argsVals.getBoolean(k);
				} else if ("object".equals(currType)) {
					sign += "_O";
					values[k + 1] = argsVals.isNull(k) ? null : argsVals.getJSONObject(k);
				} else if ("function".equals(currType)) {
					sign += "_F";
					values[k + 1] = new JsCallback(webView, mInjectedName, argsVals.getInt(k));
				} else {
					sign += "_P";
				}
			}

			Method currMethod = mMethodsMap.get(sign);

			// 方法匹配失败
			if (currMethod == null) {
				return getReturn(jsonStr, 500, "not found method(" + sign + ") with valid parameters");
			}
			// 数字类型细分匹配
			if (numIndex > 0) {
				Class[] methodTypes = currMethod.getParameterTypes();
				int currIndex;
				Class currCls;
				while (numIndex > 0) {
					currIndex = numIndex - numIndex / 10 * 10;
					currCls = methodTypes[currIndex];
					if (currCls == int.class) {
						values[currIndex] = argsVals.getInt(currIndex - 1);
					} else if (currCls == long.class) {
						// WARN: argsJson.getLong(k + defValue) will return
						// a bigger incorrect number
						values[currIndex] = Long.parseLong(argsVals.getString(currIndex - 1));
					} else {
						values[currIndex] = argsVals.getDouble(currIndex - 1);
					}
					numIndex /= 10;
				}
			}

			return getReturn(jsonStr, 200, currMethod.invoke(null, values));
		} catch (Exception e) {
			// 优先返回详细的错误信息
			if (e.getCause() != null) {
				return getReturn(jsonStr, 500, "method execute error:" + e.getCause().getMessage());
			}
			return getReturn(jsonStr, 500, "method execute error:" + e.getMessage());
		}
	} else {
		return getReturn(jsonStr, 500, "call data empty");
	}
}
 
开发者ID:PlutoArchitecture,项目名称:Pluto-Android,代码行数:77,代码来源:JsCallJava.java

示例8: call

import org.json.JSONArray; //导入方法依赖的package包/类
public String call(WebView webView, JSONObject jsonObject) {
    long time = 0;
    if (LogUtils.isDebug()) {
        time = android.os.SystemClock.uptimeMillis();
    }
    if (jsonObject != null) {
        try {
            String methodName = jsonObject.getString(KEY_METHOD);
            JSONArray argsTypes = jsonObject.getJSONArray(KEY_TYPES);
            JSONArray argsVals = jsonObject.getJSONArray(KEY_ARGS);
            String sign = methodName;
            int len = argsTypes.length();
            Object[] values = new Object[len];
            int numIndex = 0;
            String currType;

            for (int k = 0; k < len; k++) {
                currType = argsTypes.optString(k);
                if ("string".equals(currType)) {
                    sign += "_S";
                    values[k] = argsVals.isNull(k) ? null : argsVals.getString(k);
                } else if ("number".equals(currType)) {
                    sign += "_N";
                    numIndex = numIndex * 10 + k + 1;
                } else if ("boolean".equals(currType)) {
                    sign += "_B";
                    values[k] = argsVals.getBoolean(k);
                } else if ("object".equals(currType)) {
                    sign += "_O";
                    values[k] = argsVals.isNull(k) ? null : argsVals.getJSONObject(k);
                } else if ("function".equals(currType)) {
                    sign += "_F";
                    values[k] = new JsCallback(webView, mInterfacedName, argsVals.getInt(k));
                } else {
                    sign += "_P";
                }
            }

            Method currMethod = mMethodsMap.get(sign);

            // 方法匹配失败
            if (currMethod == null) {
                return getReturn(jsonObject, 500, "not found method(" + sign + ") with valid parameters", time);
            }
            // 数字类型细分匹配
            if (numIndex > 0) {
                Class[] methodTypes = currMethod.getParameterTypes();
                int currIndex;
                Class currCls;
                while (numIndex > 0) {
                    currIndex = numIndex - numIndex / 10 * 10 - 1;
                    currCls = methodTypes[currIndex];
                    if (currCls == int.class) {
                        values[currIndex] = argsVals.getInt(currIndex);
                    } else if (currCls == long.class) {
                        //WARN: argsJson.getLong(k + defValue) will return a bigger incorrect number
                        values[currIndex] = Long.parseLong(argsVals.getString(currIndex));
                    } else {
                        values[currIndex] = argsVals.getDouble(currIndex);
                    }
                    numIndex /= 10;
                }
            }

            return getReturn(jsonObject, 200, currMethod.invoke(mInterfaceObj, values), time);
        } catch (Exception e) {
            LogUtils.safeCheckCrash(TAG, "call", e);
            //优先返回详细的错误信息
            if (e.getCause() != null) {
                return getReturn(jsonObject, 500, "method execute error:" + e.getCause().getMessage(), time);
            }
            return getReturn(jsonObject, 500, "method execute error:" + e.getMessage(), time);
        }
    } else {
        return getReturn(jsonObject, 500, "call data empty", time);
    }
}
 
开发者ID:Justson,项目名称:AgentWeb,代码行数:78,代码来源:JsCallJava.java

示例9: retrieveSupplementalInfo

import org.json.JSONArray; //导入方法依赖的package包/类
@Override
void retrieveSupplementalInfo() throws IOException {

  CharSequence contents = HttpHelper.downloadViaHttp("https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn,
                                                     HttpHelper.ContentType.JSON);

  if (contents.length() == 0) {
    return;
  }

  String title;
  String pages;
  Collection<String> authors = null;

  try {

    JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue();
    JSONArray items = topLevel.optJSONArray("items");
    if (items == null || items.isNull(0)) {
      return;
    }

    JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo");
    if (volumeInfo == null) {
      return;
    }

    title = volumeInfo.optString("title");
    pages = volumeInfo.optString("pageCount");

    JSONArray authorsArray = volumeInfo.optJSONArray("authors");
    if (authorsArray != null && !authorsArray.isNull(0)) {
      authors = new ArrayList<>(authorsArray.length());
      for (int i = 0; i < authorsArray.length(); i++) {
        authors.add(authorsArray.getString(i));
      }
    }

  } catch (JSONException e) {
    throw new IOException(e);
  }

  Collection<String> newTexts = new ArrayList<>();
  maybeAddText(title, newTexts);
  maybeAddTextSeries(authors, newTexts);
  maybeAddText(pages == null || pages.isEmpty() ? null : pages + "pp.", newTexts);
  
  String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context)
      + "/search?tbm=bks&source=zxing&q=";

  append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn);
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:53,代码来源:BookResultInfoRetriever.java

示例10: a

import org.json.JSONArray; //导入方法依赖的package包/类
public final String a(WebView webView, String str) {
    if (TextUtils.isEmpty(str)) {
        return a(str, LeMessageIds.MSG_FLOAT_BALL_REQUEST_DATA, z[28]);
    }
    try {
        JSONObject jSONObject = new JSONObject(str);
        String string = jSONObject.getString(z[32]);
        JSONArray jSONArray = jSONObject.getJSONArray(z[31]);
        JSONArray jSONArray2 = jSONObject.getJSONArray(z[30]);
        int length = jSONArray.length();
        Object[] objArr = new Object[(length + 1)];
        int i = 0;
        objArr[0] = webView;
        int i2 = 0;
        while (i2 < length) {
            String str2;
            int i3;
            String optString = jSONArray.optString(i2);
            int i4;
            if (z[34].equals(optString)) {
                optString = string + z[2];
                objArr[i2 + 1] = jSONArray2.isNull(i2) ? null : jSONArray2.getString(i2);
                i4 = i;
                str2 = optString;
                i3 = i4;
            } else if (z[27].equals(optString)) {
                string = string + z[7];
                i3 = ((i * 10) + i2) + 1;
                str2 = string;
            } else if (z[33].equals(optString)) {
                optString = string + z[0];
                objArr[i2 + 1] = Boolean.valueOf(jSONArray2.getBoolean(i2));
                i4 = i;
                str2 = optString;
                i3 = i4;
            } else if (z[29].equals(optString)) {
                optString = string + z[1];
                objArr[i2 + 1] = jSONArray2.isNull(i2) ? null : jSONArray2.getJSONObject(i2);
                i4 = i;
                str2 = optString;
                i3 = i4;
            } else {
                i4 = i;
                str2 = string + z[4];
                i3 = i4;
            }
            i2++;
            string = str2;
            i = i3;
        }
        Method method = (Method) this.a.get(string);
        if (method == null) {
            return a(str, LeMessageIds.MSG_FLOAT_BALL_REQUEST_DATA, new StringBuilder(z[25]).append(string).append(z[24]).toString());
        }
        if (i > 0) {
            Class[] parameterTypes = method.getParameterTypes();
            while (i > 0) {
                i2 = i - ((i / 10) * 10);
                Class cls = parameterTypes[i2];
                if (cls == Integer.TYPE) {
                    objArr[i2] = Integer.valueOf(jSONArray2.getInt(i2 - 1));
                } else if (cls == Long.TYPE) {
                    objArr[i2] = Long.valueOf(Long.parseLong(jSONArray2.getString(i2 - 1)));
                } else {
                    objArr[i2] = Double.valueOf(jSONArray2.getDouble(i2 - 1));
                }
                i /= 10;
            }
        }
        return a(str, 200, method.invoke(null, objArr));
    } catch (Exception e) {
        return e.getCause() != null ? a(str, LeMessageIds.MSG_FLOAT_BALL_REQUEST_DATA, new StringBuilder(z[26]).append(e.getCause().getMessage()).toString()) : a(str, LeMessageIds.MSG_FLOAT_BALL_REQUEST_DATA, new StringBuilder(z[26]).append(e.getMessage()).toString());
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:75,代码来源:d.java

示例11: retrieveSupplementalInfo

import org.json.JSONArray; //导入方法依赖的package包/类
@Override
void retrieveSupplementalInfo() throws IOException {

    CharSequence contents = HttpHelper.downloadViaHttp("https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn,
            HttpHelper.ContentType.JSON);

    if (contents.length() == 0) {
        return;
    }

    String title;
    String pages;
    Collection<String> authors = null;

    try {

        JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue();
        JSONArray items = topLevel.optJSONArray("items");
        if (items == null || items.isNull(0)) {
            return;
        }

        JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo");
        if (volumeInfo == null) {
            return;
        }

        title = volumeInfo.optString("title");
        pages = volumeInfo.optString("pageCount");

        JSONArray authorsArray = volumeInfo.optJSONArray("authors");
        if (authorsArray != null && !authorsArray.isNull(0)) {
            authors = new ArrayList<>(authorsArray.length());
            for (int i = 0; i < authorsArray.length(); i++) {
                authors.add(authorsArray.getString(i));
            }
        }

    } catch (JSONException e) {
        throw new IOException(e);
    }

    Collection<String> newTexts = new ArrayList<>();
    maybeAddText(title, newTexts);
    maybeAddTextSeries(authors, newTexts);
    maybeAddText(pages == null || pages.isEmpty() ? null : pages + "pp.", newTexts);

    String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context)
            + "/search?tbm=bks&source=zxing&q=";

    append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn);
}
 
开发者ID:xiong-it,项目名称:ZXingAndroidExt,代码行数:53,代码来源:BookResultInfoRetriever.java

示例12: parseResult

import org.json.JSONArray; //导入方法依赖的package包/类
private TextList parseResult(Object result) {
    TextList empty = new TextList();

    if (result == null) {
        return empty;
    }

    String str;
    if (result instanceof String) {
        str = (String) result;
    } else if (result.getClass().isArray()) {
        Object[] arr = (Object[]) result;
        str = StringUtils.join(Arrays.asList(arr), System.lineSeparator());
    } else {
        try {
            str = toJsonString(result);
        } catch (RuntimeException e) {
            LOGGER.trace("Could not parse result", e);
            str = null;
        }
        if (str == null) {
            return empty;
        }
    }

    str = str.trim();

    JSONArray array = JsonUtils.toJsonArray(str);
    if (array == null) {
        return new TextList(new Text(str));
    } else {
        boolean allNull = true;
        for (int i = 0; i < array.length(); i++) {
            if (!array.isNull(i)) {
                allNull = false;
                break;
            }
        }
        if (allNull) {
            return empty;
        } else {
            List<Text> texts = toTextList(array);
            return new TextList(texts.iterator());
        }
    }
}
 
开发者ID:pascalgn,项目名称:jiracli,代码行数:47,代码来源:DefaultJavaScriptEngine.java


注:本文中的org.json.JSONArray.isNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。