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


Java JSONObject.keys方法代码示例

本文整理汇总了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;
}
 
开发者ID:steelkiwi,项目名称:ErrorParser,代码行数:27,代码来源:Parser.java

示例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);
    }
  }
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:27,代码来源:EventNotificationProcessor.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:33,代码来源:MobclickAgentJSInterface.java

示例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();
        }
 
开发者ID:chacaldev,项目名称:provadevida,代码行数:25,代码来源:MainActivity.java

示例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();
        }
    }
 
开发者ID:starn,项目名称:encdroidMC,代码行数:44,代码来源:Compressor.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:19,代码来源:Lights.java

示例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)));
  }
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:9,代码来源:EventsConfig.java

示例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();
}
 
开发者ID:DSM-DMS,项目名称:DMS,代码行数:24,代码来源:Request.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:18,代码来源:h.java

示例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;
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:11,代码来源:JsonMapper.java

示例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;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:40,代码来源:JSONtoFmModel.java

示例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");
	}
}
 
开发者ID:FrogSquare,项目名称:GodotFireBase,代码行数:40,代码来源:Notification.java

示例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;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:16,代码来源:SupportConfig.java

示例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;
}
 
开发者ID:ruiqiao2017,项目名称:Renrentou,代码行数:40,代码来源:JpushReceiver.java

示例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;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:34,代码来源:JavaServer.java


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