gpt4 book ai didi

Java : How to append x-times method to the object instance?

转载 作者:行者123 更新时间:2023-11-30 07:57:42 25 4
gpt4 key购买 nike

我有以下代码片段:

// Create URI object first
JSONObject requestParamsObject = null;
if (requestParams != null) {
requestParamsObject = new JSONObject(requestParams);
} else {
Logger.i("Params variable is null");
Uri.Builder builder = new Uri.Builder();
builder.scheme("http")
.encodedAuthority(url)
.appendQueryParameter("username", "test")
.appendQueryParameter("password", "password")
.appendQueryParameter("version", "2.3");
url = URLDecoder.decode(builder.build().toString(), "UTF-8");
Logger.i(url);
}

我想使用这些方法:

.appendQueryParameter("username", "test")
.appendQueryParameter("password", "password")
.appendQueryParameter("version", "2.3");

使用 for 循环附加方法。

FXP:

// Set params to request
Map<String, String> mRequestParams = new HashMap<>();
mRequestParams.put(Constants.Login.PARAM_URL_KEY_USERNAME, username);
mRequestParams.put(Constants.Login.PARAM_URL_KEY_PASSWORD, password);
mRequestParams.put(Constants.Login.PARAM_URL_KEY_APP_VERSION, "2.3"

通过类似的方式使用:

mRequestParams[i]
.appendQueryParameter(RequestParams[i].key, RequestParams[i].value)

我该怎么做?

最佳答案

怎么样:

Uri.Builder builder = new Uri.Builder();
builder.scheme("http").encodedAuthority(url);
for (Map.Entry<String, String> entry : mRequestParams.entrySet()) {
builder.appendQueryParam(entry.key, entry.value);
}
url = ...

关于Java : How to append x-times method to the object instance?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32438362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com