org.json.JSONObject.names()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(184)

本文整理了Java中org.json.JSONObject.names()方法的一些代码示例,展示了JSONObject.names()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.names()方法的具体详情如下:
包路径:org.json.JSONObject
类名称:JSONObject
方法名:names

JSONObject.names介绍

[英]Returns an array containing the string names in this object. This method returns null if this object contains no mappings.
[中]返回包含此对象中字符串名称的数组。如果此对象不包含映射,则此方法返回null。

代码示例

代码示例来源:origin: ACRA/acra

ReportMetadata(@NonNull JSONObject copyFrom) throws JSONException {
  super(copyFrom, jsonArrayToList(copyFrom.names()));
}

代码示例来源:origin: json-path/JsonPath

@Override
public Collection<String> getPropertyKeys(Object obj) {
  JSONObject jsonObject = toJsonObject(obj);
  List<String> keys = new ArrayList<String>();
  try {
    for (int i = 0; i < jsonObject.names().length(); i++) {
      String key = (String) jsonObject.names().get(i);
      keys.add(key);
    }
    return keys;
  } catch (JSONException e) {
    throw new JsonPathException(e);
  }
}

代码示例来源:origin: facebook/facebook-android-sdk

static Map<String, Object> convertJSONObjectToHashMap(JSONObject jsonObject) {
  HashMap<String, Object> map = new HashMap<String, Object>();
  JSONArray keys = jsonObject.names();
  for (int i = 0; i < keys.length(); ++i) {
    String key;
    try {
      key = keys.getString(i);
      Object value = jsonObject.get(key);
      if (value instanceof JSONObject) {
        value = convertJSONObjectToHashMap((JSONObject) value);
      }
      map.put(key, value);
    } catch (JSONException e) {
    }
  }
  return map;
}

代码示例来源:origin: ankidroid/Anki-Android

/**
 * Load registry from JSON.
 */
public void load(String json) {
  mChanged = false;
  mModels = new HashMap<>();
  try {
    JSONObject modelarray = new JSONObject(json);
    JSONArray ids = modelarray.names();
    if (ids != null) {
      for (int i = 0; i < ids.length(); i++) {
        String id = ids.getString(i);
        JSONObject o = modelarray.getJSONObject(id);
        mModels.put(o.getLong("id"), o);
      }
    }
  } catch (JSONException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: ankidroid/Anki-Android

public void load(String decks, String dconf) {
  mDecks = new HashMap<>();
  mDconf = new HashMap<>();
  try {
    JSONObject decksarray = new JSONObject(decks);
    JSONArray ids = decksarray.names();
    for (int i = 0; i < ids.length(); i++) {
      String id = ids.getString(i);
      JSONObject o = decksarray.getJSONObject(id);
      long longId = Long.parseLong(id);
      mDecks.put(longId, o);
    }
    JSONObject confarray = new JSONObject(dconf);
    ids = confarray.names();
    for (int i = 0; ids != null && i < ids.length(); i++) {
      String id = ids.getString(i);
      mDconf.put(Long.parseLong(id), confarray.getJSONObject(id));
    }
  } catch (JSONException e) {
    throw new RuntimeException(e);
  }
  mChanged = false;
}

代码示例来源:origin: json-path/JsonPath

@Override
public Iterable<?> toIterable(Object obj) {
  try {
    if (isArray(obj)) {
      JSONArray arr = toJsonArray(obj);
      List<Object> values = new ArrayList<Object>(arr.length());
      for (int i = 0; i < arr.length(); i++) {
        values.add(unwrap(arr.get(i)));
      }
      return values;
    } else {
      JSONObject jsonObject = toJsonObject(obj);
      List<Object> values = new ArrayList<Object>();
      for (int i = 0; i < jsonObject.names().length(); i++) {
        String key = (String) jsonObject.names().get(i);
        Object val = jsonObject.get(key);
        values.add(unwrap(val));
      }
      return values;
    }
  } catch (JSONException e) {
    throw new JsonPathException(e);
  }
}

代码示例来源:origin: apache/geode

/**
 *
 * @return A GfJsonArray containing the key strings, or null if the internal JSONObject is empty.
 * @throws GfJsonException If there is a syntax error while preparing GfJsonArray.
 */
public GfJsonArray names() throws GfJsonException {
 GfJsonArray gfJsonArray = new GfJsonArray();
 JSONArray names = jsonObject.names();
 if (names != null) {
  gfJsonArray = new GfJsonArray(names);
 }
 return gfJsonArray;
}

代码示例来源:origin: facebook/facebook-android-sdk

JSONObject newJsonObject = new JSONObject();
JSONObject data = new JSONObject();
JSONArray names = jsonObject.names();
for (int i = 0; i < names.length(); ++i) {
  String key = names.getString(i);

代码示例来源:origin: facebook/facebook-android-sdk

private boolean simpleJsonObjComparer(JSONObject obj1, JSONObject obj2) {
  if (obj1.names().length() != obj2.names().length()) {
    return false;
  }
  Iterator<String> keys = obj1.keys();
  while (keys.hasNext()) {
    try {
      String key = keys.next();
      Object value1 = obj1.get(key);
      Object value2 = obj2.get(key);
      if (!jsonObjectValueComparer(value1, value2)){
        return false;
      }
    } catch (Exception ex) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: loklak/loklak_server

/**
 * Produce a comma delimited text from a JSONArray of JSONObjects. The
 * first row will be a list of names obtained by inspecting the first
 * JSONObject.
 * @param ja A JSONArray of JSONObjects.
 * @return A comma delimited text.
 * @throws JSONException
 */
public static String toString(JSONArray ja) throws JSONException {
  JSONObject jo = ja.optJSONObject(0);
  if (jo != null) {
    JSONArray names = jo.names();
    if (names != null) {
      return rowToString(names) + toString(names, ja);
    }
  }
  return null;
}

代码示例来源:origin: ankidroid/Anki-Android

if (i > 0) {
  JSONObject presetValues = new JSONObject(dynExamples[i]);
  JSONArray ar = presetValues.names();
  for (int j = 0; j < ar.length(); j++) {
    String name = ar.getString(j);

代码示例来源:origin: cloudfoundry/uaa

@Override
public boolean matches(Object item) {
  if(!String.class.isInstance(item)){
    return false;
  }
  if(this.expected == null && "null".equals(item)){
    return true;
  }
  JSONObject actual = null;
  try {
    actual = new JSONObject(new JSONTokener(item.toString()));
  } catch (JSONException e) {
    return false;
  }
  if(this.expected.length() != actual.length()) {
    return false;
  }
  JSONArray names = actual.names();
  for(int i = 0, len = names.length(); i < len; i++){
    try {
      String name = names.getString(i);
      if(!Objects.equals(expected.get(name), actual.get(name))){
        return false;
      }
    } catch (JSONException e) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: ukanth/afwall

public static boolean isEmptyObject(JSONObject object) {
  return object.names() == null;
}

代码示例来源:origin: chat-sdk/chat-sdk-android

public static boolean isEmptyObject(JSONObject object) {
  return object.names() == null;
}

代码示例来源:origin: ankidroid/Anki-Android

JSONArray keys = media.names();
if (keys != null) {
  for (int i = 0; i < keys.length(); i++) {

代码示例来源:origin: com.jayway.jsonpath/json-path

@Override
public Collection<String> getPropertyKeys(Object obj) {
  JSONObject jsonObject = toJsonObject(obj);
  List<String> keys = new ArrayList<String>();
  try {
    for (int i = 0; i < jsonObject.names().length(); i++) {
      String key = (String) jsonObject.names().get(i);
      keys.add(key);
    }
    return keys;
  } catch (JSONException e) {
    throw new JsonPathException(e);
  }
}

代码示例来源:origin: com.jayway.jsonpath/json-path

@Override
public Iterable<?> toIterable(Object obj) {
  try {
    if (isArray(obj)) {
      JSONArray arr = toJsonArray(obj);
      List<Object> values = new ArrayList<Object>(arr.length());
      for (int i = 0; i < arr.length(); i++) {
        values.add(unwrap(arr.get(i)));
      }
      return values;
    } else {
      JSONObject jsonObject = toJsonObject(obj);
      List<Object> values = new ArrayList<Object>();
      for (int i = 0; i < jsonObject.names().length(); i++) {
        String key = (String) jsonObject.names().get(i);
        Object val = jsonObject.get(key);
        values.add(unwrap(val));
      }
      return values;
    }
  } catch (JSONException e) {
    throw new JsonPathException(e);
  }
}

代码示例来源:origin: b3log/latke

/**
 * Produce a comma delimited text from a JSONArray of JSONObjects. The
 * first row will be a list of names obtained by inspecting the first
 * JSONObject.
 * @param ja A JSONArray of JSONObjects.
 * @return A comma delimited text.
 * @throws JSONException
 */
public static String toString(JSONArray ja) throws JSONException {
  JSONObject jo = ja.optJSONObject(0);
  if (jo != null) {
    JSONArray names = jo.names();
    if (names != null) {
      return rowToString(names) + toString(names, ja);
    }
  }
  return null;
}

代码示例来源:origin: b3log/latke

final JSONArray names = jsonObject.names();
final Set<Object> nameSet = CollectionUtils.jsonArrayToSet(names);

代码示例来源:origin: mobnetic/BitcoinChecker

@Override
protected void parseTickerFromJsonObject(int requestId, JSONObject jsonObject, Ticker ticker, CheckerInfo checkerInfo) throws Exception {
  final JSONObject marketsJsonObject = jsonObject.getJSONObject("markets");
  final JSONArray marketNames = marketsJsonObject.names();
  final JSONObject marketJsonObject = marketsJsonObject.getJSONObject(marketNames.getString(0));
  
  ticker.bid = getFirstOrderFrom(marketJsonObject, "buy_orders");
  ticker.ask = getFirstOrderFrom(marketJsonObject, "sell_orders");
  ticker.vol = marketJsonObject.getDouble("volume");
  ticker.high = marketJsonObject.getDouble("high");
  ticker.low = marketJsonObject.getDouble("low");
  ticker.last = marketJsonObject.getDouble("last_price");
}

相关文章

JSONObject类方法