本文整理汇总了Java中org.json.JSONObject.keys方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.keys方法的具体用法?Java JSONObject.keys怎么用?Java JSONObject.keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.keys方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toMap
import org.json.JSONObject; //导入方法依赖的package包/类
private static Map<String, Object> toMap(JSONObject object) throws JSONException {
Map<String, Object> map = new HashMap<String, Object>();
Iterator<String> keysItr = object.keys();
while (keysItr.hasNext()) {
String key = keysItr.next();
Object value = object.get(key);
if (isValueValid(value.toString())) {
notNestingMap.put(key, value);
}
if (value instanceof JSONArray) {
value = toList((JSONArray) value);
} else if (value instanceof JSONObject) {
value = toMap((JSONObject) value);
}
if (value instanceof List) {
if (!((List<Object>) value).isEmpty()) {
map.put(key, value);
}
} else if (isValueValid(value.toString())) {
map.put(key, value);
}
}
clearUpMap(map);
return map;
}
示例2: loadMessageMap
import org.json.JSONObject; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void loadMessageMap(String jsonString) throws JSONException {
JSONObject messageMapJson = new JSONObject(jsonString);
// Get subscriber event specs.
if (messageMapJson != null) {
Iterator<String> keys = messageMapJson.keys();
while (keys.hasNext()) {
String userId = keys.next();
JSONObject eventToMessagesJson = messageMapJson.optJSONObject(userId);
if (eventToMessagesJson == null) {
continue;
}
// Get the eventId --> message-list mapping
Map<String, List<String>> eventNameToMessages = new HashMap<String, List<String>>();
Iterator<String> eventNames = eventToMessagesJson.keys();
while (eventNames.hasNext()) {
String eventName = eventNames.next();
List<String> messages = JsonUtil.toList(eventToMessagesJson.optJSONArray(eventName));
if (messages != null && !messages.isEmpty()) {
eventNameToMessages.put(eventName, messages);
}
}
messageMap.put(userId, eventNameToMessages);
}
}
}
示例3: onJsPrompt
import org.json.JSONObject; //导入方法依赖的package包/类
public boolean onJsPrompt(WebView webView, String str, String str2, String str3, JsPromptResult jsPromptResult) {
if ("ekv".equals(str2)) {
try {
JSONObject jSONObject = new JSONObject(str3);
Map hashMap = new HashMap();
String str4 = (String) jSONObject.remove("id");
int intValue = jSONObject.isNull(DownloadVideoTable.COLUMN_DURATION) ? 0 : ((Integer) jSONObject.remove(DownloadVideoTable.COLUMN_DURATION)).intValue();
Iterator keys = jSONObject.keys();
while (keys.hasNext()) {
String str5 = (String) keys.next();
hashMap.put(str5, jSONObject.getString(str5));
}
MobclickAgent.getAgent().a(this.b.a, str4, hashMap, (long) intValue);
} catch (Exception e) {
e.printStackTrace();
}
} else if (!NotificationCompat.CATEGORY_EVENT.equals(str2)) {
return this.a.onJsPrompt(webView, str, str2, str3, jsPromptResult);
} else {
try {
JSONObject jSONObject2 = new JSONObject(str3);
String optString = jSONObject2.optString("label");
if ("".equals(optString)) {
optString = null;
}
MobclickAgent.getAgent().a(this.b.a, jSONObject2.getString("tag"), optString, (long) jSONObject2.optInt(DownloadVideoTable.COLUMN_DURATION), 1);
} catch (Exception e2) {
}
}
jsPromptResult.confirm();
return true;
}
示例4: getPostDataString
import org.json.JSONObject; //导入方法依赖的package包/类
public String getPostDataString(JSONObject params) throws Exception {
StringBuilder result = new StringBuilder();
boolean first = true;
Iterator<String> itr = params.keys();
while(itr.hasNext()){
String key= itr.next();
Object value = params.get(key);
if (first)
first = false;
else
result.append("&");
result.append(URLEncoder.encode(key, "UTF-8"));
result.append("=");
result.append(URLEncoder.encode(value.toString(), "UTF-8"));
}
return result.toString();
}
示例5: writeObject
import org.json.JSONObject; //导入方法依赖的package包/类
/**
* Write a JSON object.
*
* @param jsonobject
* @return
* @throws JSONException
*/
private void writeObject(JSONObject jsonobject) throws JSONException {
// JSONzip has two encodings for objects: Empty Objects (zipEmptyObject) and
// non-empty objects (zipObject).
boolean first = true;
Iterator keys = jsonobject.keys();
while (keys.hasNext()) {
if (probe) {
log("\n");
}
Object key = keys.next();
if (key instanceof String) {
if (first) {
first = false;
write(zipObject, 3);
} else {
one();
}
writeName((String) key);
Object value = jsonobject.get((String) key);
if (value instanceof String) {
zero();
writeString((String) value);
} else {
one();
writeValue(value);
}
}
}
if (first) {
write(zipEmptyObject, 3);
} else {
zero();
}
}
示例6: getSubLightMap
import org.json.JSONObject; //导入方法依赖的package包/类
public static List<Light> getSubLightMap(JSONObject object) throws JSONException {
List<Light> list = new ArrayList();
List<Light> listStatic = Light.getsubLightsList();
int i = 0;
while (i < listStatic.size()) {
Iterator<String> keys = object.keys();
while (keys.hasNext()) {
String key = (String) keys.next();
if (!(key.equals("fat") || key.equals("saturated_fat") || key.equals("sugar") ||
key.equals("fiber_dietary") || key.equals("natrium") || !((Light)
listStatic.get(i)).element.equals(key))) {
list.add(new Light(key, ((Integer) object.get(key)).intValue()));
}
}
i++;
}
return list;
}
示例7: EventsConfig
import org.json.JSONObject; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public EventsConfig(JSONObject json) throws JSONException {
Iterator<String> keys = json.keys();
while (keys.hasNext()) {
String key = keys.next();
eventSpecs.put(key, new EventSpec(json.getJSONArray(key)));
}
}
示例8: getFormString
import org.json.JSONObject; //导入方法依赖的package包/类
public String getFormString(JSONObject params) throws JSONException {
StringBuilder result = new StringBuilder();
boolean isFirst = true; // 첫 번째 매개변수 여부
Iterator<String> keys = params.keys();
while (keys.hasNext()) {
String key = keys.next();
String value = params.getString(key);
if (isFirst) isFirst = false;
else result.append("&"); // 첫 번째 매개변수가 아닌 경우엔 앞에 &를 붙임
try { // UTF-8로 주소에 키와 값을 붙임
result.append(URLEncoder.encode(key, "UTF-8"));
result.append("=");
result.append(URLEncoder.encode(value, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return result.toString();
}
示例9: a
import org.json.JSONObject; //导入方法依赖的package包/类
public static Map<String, String> a(JSONObject jSONObject) {
Map<String, String> map = null;
if (jSONObject == null) {
return null;
}
Map<String, String> hashMap = new HashMap();
Iterator keys = jSONObject.keys();
while (keys.hasNext()) {
String str = (String) keys.next();
try {
map = jSONObject.getString(str);
} catch (JSONException e) {
}
hashMap.put(str, map);
}
return hashMap;
}
示例10: unwrapJsonObject
import org.json.JSONObject; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static Map<String, Object> unwrapJsonObject(JSONObject jsonObject) throws JSONException {
Map<String, Object> map = new HashMap<>(jsonObject.length());
Iterator<String> keys = jsonObject.keys();
while (keys.hasNext()) {
String key = keys.next();
map.put(key, unwrapJson(jsonObject.get(key)));
}
return map;
}
示例11: convertJSONObjectToMap
import org.json.JSONObject; //导入方法依赖的package包/类
/**
* JSONObject is an unordered collection of name/value pairs -> convert to Map (equivalent to Freemarker "hash")
*/
@SuppressWarnings("unchecked")
public static Map<String, Object> convertJSONObjectToMap(JSONObject jo) throws JSONException
{
Map<String, Object> model = new HashMap<String, Object>();
Iterator<String> itr = (Iterator<String>)jo.keys();
while (itr.hasNext())
{
String key = (String)itr.next();
Object o = jo.get(key);
if (o instanceof JSONObject)
{
model.put(key, convertJSONObjectToMap((JSONObject)o));
}
else if (o instanceof JSONArray)
{
model.put(key, convertJSONArrayToList((JSONArray)o));
}
else if (o == JSONObject.NULL)
{
model.put(key, null); // note: http://freemarker.org/docs/dgui_template_exp.html#dgui_template_exp_missing
}
else
{
if ((o instanceof String) && autoConvertISO8601 && (matcherISO8601.matcher((String)o).matches()))
{
o = ISO8601DateFormat.parse((String)o);
}
model.put(key, o);
}
}
return model;
}
示例12: init
import org.json.JSONObject; //导入方法依赖的package包/类
public void init (FirebaseApp firebaseApp) {
mFirebaseApp = firebaseApp;
String token = getFirebaseMessagingToken();
dispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(activity.getApplicationContext()));
dispatcher.cancel("firebase-notify-in-time-UID");
Utils.d("Firebase Cloud messaging token: " + token);
// Perform task here..!
if (KeyValueStorage.getValue("notification_complete_task") != "0") {
try {
JSONObject obj =
new JSONObject(KeyValueStorage.getValue("notification_task_data"));
Dictionary data = new Dictionary();
Iterator<String> iterator = obj.keys();
while (iterator.hasNext()) {
String key = iterator.next();
Object value = obj.opt(key);
if (value != null) {
data.put(key, value);
}
}
Utils.callScriptCallback(
KeyValueStorage.getValue("notification_complete_task"),
"Notification", "TaskComplete", data);
} catch (JSONException e) {
}
KeyValueStorage.setValue("notification_complete_task", "0");
}
}
示例13: getSupportMap
import org.json.JSONObject; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public static Map<String, SupportConfig> getSupportMap(JSONObject json) {
Map<String, SupportConfig> map = new HashMap<String, SupportConfig>();
// Get the roles
Iterator keys = json.keys();
while (keys.hasNext()) {
String key = (String) keys.next();
try {
map.put(key, new SupportConfig(json.getJSONObject(key)));
} catch (Exception e) {
// do nothing
}
}
return map;
}
示例14: getMessage
import org.json.JSONObject; //导入方法依赖的package包/类
private MyMessage getMessage(Bundle bundle){
MyMessage message = new MyMessage();
message.setIsScanned(0);
for (String key : bundle.keySet()) {
if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
message.setNotifyId(String.valueOf(bundle.getInt(key)));
}else if(key.equals(JPushInterface.EXTRA_ALERT)){
message.setAlert(bundle.getString(key));
} else if (key.equals(JPushInterface.EXTRA_MSG_ID)) {
message.setMsgId(bundle.getString(key));
} else if (key.equals(JPushInterface.EXTRA_ALERT_TYPE)) {
message.setType(bundle.getString(key));
}else if (key.equals(JPushInterface.EXTRA_EXTRA)) {
if (TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) {
Log.d(TAG, "This message has no Extra data");
continue;
}
try {
JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
Iterator<String> it = json.keys();
while (it.hasNext()) {
String myKey = it.next().toString();
if(myKey.equals("title")){
message.setTitle(json.optString(myKey));
}else if(myKey.equals("date")){
message.setDate(json.optString(myKey));
}
}
} catch (JSONException e) {
Log.e(TAG, "Get message extra JSON error!");
}
}
}
return message;
}
示例15: updateCapabilities
import org.json.JSONObject; //导入方法依赖的package包/类
public String updateCapabilities(JSONObject caps) {
@SuppressWarnings("rawtypes")
Iterator keys = caps.keys();
while (keys.hasNext()) {
String key = (String) keys.next();
if (!hasCapabilities.has(key)) {
return "Do not have the capability by name " + key;
}
Object rvalue = caps.get(key);
capabilities.put(key, rvalue);
if (rvalue instanceof Boolean && !((Boolean) rvalue).booleanValue()) {
continue;
}
Object lvalue = hasCapabilities.get(key);
if (!lvalue.equals(rvalue)) {
if (key.equals("loggingPrefs")) {
continue;
}
if (key.equals("platform")) {
Platform lPlatform = Platform.valueOf((String) lvalue);
Platform rPlatform = Platform.valueOf((String) rvalue);
if (rPlatform.is(lPlatform)) {
continue;
}
}
if (key.equals("version") && rvalue.equals("")) {
continue;
}
return "Java Driver does not support `" + key + "`" + (rvalue instanceof Boolean ? "" : " for value " + rvalue);
}
}
return null;
}