我想在对象中创建所有键的数组吗?有人知道如何在Android中执行此操作吗?在iOS中我已经完成了这个
NSDictionary *variablesDictionary = [[NSDictionary alloc] init];
// ^^ full of variables and keys...
NSString *finalString = @"";
if(variablesDictionary != nil){
NSArray *keysArray = [variablesDictionary allKeys];
for(NSString *singleKey in keysArray) {
finalString = [finalString stringByAppendingString:[NSString stringWithFormat:@"&%@=%@", singleKey, [variablesDictionary objectForKey:singleKey]]];
}
}
//final string will = '&key=variable&key=variable&key=variable&key=variable' etc...
这是我迄今为止所尝试的内容。继承我的全球行动
public final static void startAPICallRequest(Context activityContext, String request, String apiLocation, Object postVarsObj, Object getVarsObj){
long unixTimeStamp = System.currentTimeMillis() / 1000L;
if(getVarsObj != null){
Array keysArray = getVarsObj.keySet().toArray();
StringBuilder sb = new StringBuilder();
for (String key : getVarsObj.keySet()) {
sb.append("&");
sb.append(key);
sb.append("=");
sb.append(getVarsObj.get(key).toString());
}
final String will = sb.toString();
}
}
答案 0 :(得分:0)
// for Map<String, Object>
StringBuilder sb = new StringBuilder();
for (String key : map.keySet()) {
sb.append("&");
sb.append(key);
sb.append("=");
sb.append(map.get(key).toString());
}
final String will = sb.toString();
答案 1 :(得分:0)
如果使用地图,您需要查看keySet()功能。 Here is an example