當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONObject.get方法代碼示例

本文整理匯總了Java中org.json.JSONObject.get方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.get方法的具體用法?Java JSONObject.get怎麽用?Java JSONObject.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.json.JSONObject的用法示例。


在下文中一共展示了JSONObject.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toFlatStringMap

import org.json.JSONObject; //導入方法依賴的package包/類
/**
 * Convert json object into simple string-string map.
 * Non-string values are ignored.
 *
 * @param object json object to convert
 * @return resulting map
 * @throws JSONException when json object is invalid
 */
public static Map<String, String> toFlatStringMap(final JSONObject object) throws JSONException {
    final Map<String, String> map = new HashMap<String, String>();
    final Iterator<String> keysItr = object.keys();
    while (keysItr.hasNext()) {
        final String key = keysItr.next();
        final Object value = object.get(key);
        if (!(value instanceof String)) {
            continue;
        }

        map.put(key, (String) value);
    }

    return map;
}
 
開發者ID:SUTFutureCoder,項目名稱:localcloud_fe,代碼行數:24,代碼來源:JSONUtils.java

示例2: update

import org.json.JSONObject; //導入方法依賴的package包/類
/**
 * Update configurations for a list of keys
 *
 * @param keys - list of config key to migrate
 */
public static boolean update(List<String> keys) {
  try {
    Map<String, String> conf = readConfig(keys);
    if (conf == null) {
      return false;
    }
    List<String> confSystem = new ArrayList<>(0);
    //process
    for (String domainId : conf.keySet()) {
      xLog.info("Parsing config for domain {0}", domainId);
      JSONObject config = new JSONObject(conf.get(domainId));
      JSONObject inventory = (JSONObject) config.get("invntry");
      JSONObject optmz = (JSONObject) config.get("optmz");
      String compute = (String) optmz.get("compute");
      if (inventory.has("cr") || inventory.has("dispcr")) {
        xLog.info("New configuration already set for: {0}", domainId);
        confSystem.add(domainId);
        continue;
      }
      if (optmz.has("compute-crfreqs")) {
        optmz.remove("compute-crfreqs");
      }
      if (inventory.has("manualcr")) {
        String manualcr = (String) inventory.get("manualcr");
        inventory.put("cr", "0");
        inventory.put("manualcrfreq", manualcr);
        inventory.put("dispcr", true);
        inventory.put("dcrfreq", manualcr);
        optmz.put("compute", "-1");
        inventory.remove("manualcr");
        xLog.info("Configuration set for manualcr: {0}" + domainId);
      } else if ("0".equals(compute)) {
        inventory.put("cr", "1");
        inventory.put("dispcr", false);
        optmz.put("compute", "-1");
        xLog.info("Configuration set for Automatic: {0}" + domainId);
      } else if ("100".equals(compute) || "200".equals(compute)) {
        inventory.put("cr", "1");
        inventory.put("dispcr", false);
        xLog.info("Configuration set for Demand forecast/OOQ: {0}" + domainId);
      } else if ("-1".equals(compute)) {
        inventory.put("cr", "-1");
        inventory.put("dispcr", false);
        xLog.info("Configuration set for forecasting as NONE: {0}" + domainId);
      }
      inventory.put("showpr", false);
      config.put("invntry", inventory);
      config.put("optmz", optmz);
      conf.put(domainId, String.valueOf(config));
    }
    //update
    ps = connection.prepareStatement(CONFIG_UPDATE_QUERY);
    for (String confKeys : conf.keySet()) {
      if (!confSystem.contains(confKeys)) {
        ps.setString(1, conf.get(confKeys));
        ps.setString(2, confKeys);
        ps.addBatch();
      }
    }
    int[] count = ps.executeBatch();
    xLog.info("{0} domains updated out of {1}", count.length, conf.size());
  } catch (Exception e) {
    xLog.warn("Error in updating configuration: " + e);
    return false;
  } finally {
    if (ps != null) {
      try {
        ps.close();
      } catch (SQLException ignored) {
        xLog.warn("Exception while closing prepared statement", ignored);
      }
    }
  }
  return true;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:81,代碼來源:CRConfigMigrator.java

示例3: build

import org.json.JSONObject; //導入方法依賴的package包/類
public void build(String data){

        try {
            // PHP에서 받아온 JSON 데이터를 JSON오브젝트로 변환
            JSONObject jObject = new JSONObject(data);
            // results라는 key는 JSON배열로 되어있다.
            JSONArray results = jObject.getJSONArray("result");
            String countTemp = (String)jObject.get("num_result");
            int count = Integer.parseInt(countTemp);

            for ( int i = 0; i < count; ++i ) {
                JSONObject temp = results.getJSONObject(i);
                convert(temp);

            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

    }
 
開發者ID:pooi,項目名稱:Nearby,代碼行數:22,代碼來源:MedicineDetail.java

示例4: deepMerge

import org.json.JSONObject; //導入方法依賴的package包/類
/**
 * Merge "source" into "target". If fields have equal name, merge them recursively.
 *
 * @param target On merge conflicts this object loses
 * @param source On merge conflicts this object wins
 * @return the merged object (target).
 * @throws JSONException the json exception
 * @source http ://stackoverflow.com/a/15070484/1507692
 */
public static JSONObject deepMerge(final JSONObject target, final JSONObject source) throws JSONException {
    final JSONObject newObject = new JSONObject(target.toString());
    final Iterator keys = source.keys();
    while (keys.hasNext()) {
        final String key = keys.next().toString();
        final Object value = source.get(key);

        if (!newObject.has(key)) {
            newObject.put(key, value);
        } else {
            newObject.put(key, merge(newObject.get(key), value));
        }
    }
    return newObject;
}
 
開發者ID:mhaddon,項目名稱:Sound.je,代碼行數:25,代碼來源:JSONUtil.java

示例5: toMap

import org.json.JSONObject; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static Map<String, Object> toMap(JSONObject json) throws JSONException {
  if (json == null) {
    return null;
  }
  Map<String, Object> map = new HashMap<String, Object>();
  Iterator<String> keys = json.keys();
  while (keys.hasNext()) {
    String key = keys.next();
    Object o = json.get(key);
    if (o instanceof JSONArray) {
      map.put(key, toList((JSONArray) o));
    } else if (o instanceof JSONObject) {
      map.put(key, toMap((JSONObject) o));
    } else {
      map.put(key, o);
    }
  }
  return map;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:21,代碼來源:JsonUtil.java

示例6: jsonToReact

import org.json.JSONObject; //導入方法依賴的package包/類
public static WritableMap jsonToReact(JSONObject jsonObject) throws JSONException {
    WritableMap writableMap = Arguments.createMap();
    Iterator iterator = jsonObject.keys();
    while(iterator.hasNext()) {
        String key = (String) iterator.next();
        Object value = jsonObject.get(key);
        if (value instanceof Float || value instanceof Double) {
            writableMap.putDouble(key, jsonObject.getDouble(key));
        } else if (value instanceof Number) {
            writableMap.putInt(key, jsonObject.getInt(key));
        } else if (value instanceof String) {
            writableMap.putString(key, jsonObject.getString(key));
        } else if (value instanceof JSONObject) {
            writableMap.putMap(key,jsonToReact(jsonObject.getJSONObject(key)));
        } else if (value instanceof JSONArray){
            writableMap.putArray(key, jsonToReact(jsonObject.getJSONArray(key)));
        } else if (value == JSONObject.NULL){
            writableMap.putNull(key);
        }
    }

    return writableMap;
}
 
開發者ID:whitedogg13,項目名稱:react-native-nfc-manager,代碼行數:24,代碼來源:JsonConvert.java

示例7: readMap

import org.json.JSONObject; //導入方法依賴的package包/類
/**
 * Reads a stored mapped from the JSON object and populates the data
 * structure
 * 
 * @param <U>
 * @param <V>
 * @param map
 * @param name
 * @param key_map
 * @param object
 * @throws JSONException
 */
@SuppressWarnings("unchecked")
protected <U, V> void readMap(SortedMap<U, V> map, String name, Map<String, U> key_map, Class<?> value_class, JSONObject object) throws JSONException {
    map.clear();
    JSONObject jsonObject = object.getJSONObject(name);
    Iterator<String> keys = jsonObject.keys();
    boolean first = true;
    while (keys.hasNext()) {
        String key_name = keys.next();
        U key_object = null;
        V value = null;

        if (value_class.equals(Long.class)) {
            value = (V) new Long(jsonObject.getLong(key_name));
        } else {
            value = (V) jsonObject.get(key_name);
        }
        key_object = key_map.get(key_name);
        if (key_object == null) {
            LOG.warn("Failed to retrieve key object '" + key_name + "' for " + name);
            if (LOG.isDebugEnabled() && first) {
                LOG.warn(jsonObject.toString(2));
            }
            first = false;
            continue;
        }
        map.put(key_object, value);
    } // FOR
    LOG.debug("Added " + map.size() + " values to " + name);
    return;
}
 
開發者ID:s-store,項目名稱:s-store,代碼行數:43,代碼來源:AbstractStatistics.java

示例8: getJSONValue

import org.json.JSONObject; //導入方法依賴的package包/類
private String getJSONValue(JSONObject obj, String propName)
{
	String value = null;
	if (obj.has(propName)) {
		Object obj2 = obj.get(propName);
		if (obj2 != null)
			value = obj2.toString();
	}
	
	return value;
}
 
開發者ID:GIScience,項目名稱:openrouteservice,代碼行數:12,代碼來源:NominatimGeocoder.java

示例9: fromJSONString

import org.json.JSONObject; //導入方法依賴的package包/類
/**
 * Load the object from the JSON string
 */
public void fromJSONString(String jsonString) throws ProtocolException {
  try {
    JSONObject json = new JSONObject(jsonString);
    // Get the version
    this.version = (String) json.get(JsonTagsZ.VERSION);
    if ("01".equals(this.version)) {
      loadFromJSON01(json);
    } else {
      throw new ProtocolException("Unsupported protocol version: " + this.version);
    }
  } catch (JSONException e) {
    throw new ProtocolException(e.getMessage());
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:18,代碼來源:GetOrdersOutput.java

示例10: getCellRows

import org.json.JSONObject; //導入方法依賴的package包/類
public int[] getCellRows(JSONObject rowObject) {
    JSONArray x = (JSONArray) rowObject.get("rows");
    int[] rows = new int[x.length()];
    for (int i = 0; i < x.length(); i++) {
        rows[i] = x.getInt(i);
    }
    return rows;
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:9,代碼來源:JavaFXElementPropertyAccessor.java

示例11: handleErrorResponse

import org.json.JSONObject; //導入方法依賴的package包/類
private void handleErrorResponse(JSONObject response) {
    if (response.has("code")) {
        if (!(response.get("code") instanceof Integer)) return;
        ErrorResponse errorResponse = ErrorResponse.getByKey(response.getInt("code"));
        if (errorResponse != ErrorResponse.UNKNOWN) {
            throw new ErrorResponseException(errorResponse);
        } else {
            throw new ErrorResponseException(response.getInt("code"), response.getString("message"));
        }
    }
}
 
開發者ID:AlienIdeology,項目名稱:J-Cord,代碼行數:12,代碼來源:Requester.java

示例12: putIntentExtra

import org.json.JSONObject; //導入方法依賴的package包/類
/**
 * 將jsnon數據傳入Intent傳遞給本地頁麵
 *
 * @param jsonObject
 * @param intent
 * @return
 * @throws JSONException
 */
public static Intent putIntentExtra(JSONObject jsonObject, Intent intent) throws JSONException {
    if (jsonObject == null || intent == null) {
        return null;
    }
    Iterator<String> it = jsonObject.keys();
    while (it.hasNext()) {
        String key = it.next();
        Object valueObj = jsonObject.get(key);
        if (valueObj instanceof Boolean) {
            intent.putExtra(key, (boolean) valueObj);
        } else if (valueObj instanceof String) {
            intent.putExtra(key, valueObj.toString());
        } else if (valueObj instanceof Integer) {
            intent.putExtra(key, (int) valueObj);
        } else if (valueObj instanceof Double) {
            intent.putExtra(key, (Double) valueObj);
        } else if (valueObj instanceof Float) {
            intent.putExtra(key, (Float) valueObj);
        } else if (valueObj instanceof Byte) {
            intent.putExtra(key, (Byte) valueObj);
        } else if (valueObj instanceof Short) {
            intent.putExtra(key, (Short) valueObj);
        } else if (valueObj instanceof Long) {
            intent.putExtra(key, (Long) valueObj);
        } else {
            intent.putExtra(key, valueObj.toString());
        }
    }
    return intent;
}
 
開發者ID:quickhybrid,項目名稱:quickhybrid-android,代碼行數:39,代碼來源:QuickUtil.java

示例13: getFromJsonByField2

import org.json.JSONObject; //導入方法依賴的package包/類
/**
 * 
 * @param json
 * @param key
 * @param toField
 * @return
 * @throws JSONException
 */
public static Object getFromJsonByField2(JSONObject json, String key, Field toField) throws JSONException {
	final Object o = json.get(key);
	final Class<?> fieldType = toField.getType();
	if (o != JSONObject.NULL) {
		if (fieldType.equals(Integer.class) || fieldType.equals(Integer.TYPE)) {
			return json.getInt(key);
		}
		else if (fieldType.equals(String.class)) {
			return o;
		}
		else if (fieldType.equals(Long.class) || fieldType.equals(Long.TYPE)) {
			return json.getLong(key);
		}
		else if (fieldType.equals(Boolean.class) || fieldType.equals(Boolean.TYPE)) {
			return json.getBoolean(key);
		}
		else if (fieldType.equals(Float.class) || fieldType.equals(Float.TYPE)) {
			return (float) json.getDouble(key);
		}
		else if (fieldType.equals(Double.class) || fieldType.equals(Double.TYPE)) {
			return json.getDouble(key);
		}
		else {
			return o;
		}			
	}

	return JSONObject.NULL;
}
 
開發者ID:rtr-nettest,項目名稱:open-rmbt,代碼行數:38,代碼來源:HstoreParser.java

示例14: testJsonFormData

import org.json.JSONObject; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void testJsonFormData() throws Exception
{
    JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
    String jsonPostString = jsonPostData.toString();
    Response rsp = sendRequest(new PostRequest(FORM_DEF_URL, 
                jsonPostString, APPLICATION_JSON), 200);
    String jsonResponseString = rsp.getContentAsString();

    JSONObject jsonParsedObject = new JSONObject(new JSONTokener(jsonResponseString));
    assertNotNull(jsonParsedObject);
    
    JSONObject rootDataObject = (JSONObject)jsonParsedObject.get("data");
    
    JSONObject formDataObject = (JSONObject)rootDataObject.get("formData");
    List<String> keys = new ArrayList<String>();
    for (Iterator iter = formDataObject.keys(); iter.hasNext(); )
    {
        String nextFieldName = (String)iter.next();
        assertEquals("Did not expect to find a colon char in " + nextFieldName,
                    -1, nextFieldName.indexOf(':'));
        keys.add(nextFieldName);
    }
    // Threshold is a rather arbitrary number. I simply want to ensure that there
    // are *some* entries in the formData hash.
    final int threshold = 5;
    int actualKeyCount = keys.size();
    assertTrue("Expected more than " + threshold +
            " entries in formData. Actual: " + actualKeyCount, actualKeyCount > threshold);
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:31,代碼來源:FormRestApiGet_Test.java

示例15: PurchaseSalesOrderConfig

import org.json.JSONObject; //導入方法依賴的package包/類
public PurchaseSalesOrderConfig(JSONObject jsonObject) {
  if (jsonObject != null && jsonObject.length() > 0) {
    try {
      JSONArray jsonArray = jsonObject.getJSONArray(ENTITY_TAGS);
      et = new ArrayList<>();
      for (int i = 0; i < jsonArray.length(); i++) {
        Object obj = jsonArray.get(i);
        et.add((String) obj);
      }

    } catch (JSONException e) {
      et = new ArrayList<>(1);
    }

    if (jsonObject.get(SALES_ORDER_APPROVAL) != null) {
      soa = jsonObject.getBoolean(SALES_ORDER_APPROVAL);
    }
    if (jsonObject.get(PURCHASE_ORDER_APPROVAL) != null) {
      poa = jsonObject.getBoolean(PURCHASE_ORDER_APPROVAL);
    }
    if (jsonObject.get(SALES_ORDER_APPROVAL_CREATION) != null) {
      soac = jsonObject.getBoolean(SALES_ORDER_APPROVAL_CREATION);
    }
    if (jsonObject.get(SALES_ORDER_APPROVAL_SHIPPING) != null) {
      soas = jsonObject.getBoolean(SALES_ORDER_APPROVAL_SHIPPING);
    }
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:29,代碼來源:ApprovalsConfig.java


注:本文中的org.json.JSONObject.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。