得到关键名称&来自json的关键价值 [英] get key name & key value from json
本文介绍了得到关键名称&来自json的关键价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对java很新。我如何获得关键名称&这个jsonobject&的关键价值将它传递给我的增量方法?
I'm totally new to java. How do I get the key name & key value of this jsonobject & pass it to my increment method?
args = {'property_name':1}
private boolean handlePeopleIncrement(JSONArray args, final CallbackContext cbCtx) {
JSONObject json_array = args.optJSONObject(0);
mixpanel.getPeople().increment(key_name, key_value);
cbCtx.success();
return true;
}
更新
现在我收到错误:
Object cannot be converted to Number
Number value = json_array.get(key);
-
private boolean handlePeopleIncrement(JSONArray args, final CallbackContext cbCtx) {
JSONObject json_array = args.optJSONObject(0);
Iterator<?> keys = json_array.keys();
while( keys.hasNext() ) {
String key = (String) keys.next();
Number value = json_array.get(key);
// System.out.println("Key: " + key);
// System.out.println("Value: " + json_array.get(key));
}
mixpanel.getPeople().increment(key, value);
cbCtx.success();
return true;
}
推荐答案
尝试使用此
JSONObject json_array = args.optJSONObject(0);
Iterator<?> keys = json_array.keys();
while( keys.hasNext() ) {
String key = (String) keys.next();
System.out.println("Key: " + key);
System.out.println("Value: " + json_array.get(key));
}
这篇关于得到关键名称&来自json的关键价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文