本文整理汇总了Java中org.json.JSONObject.accumulate方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.accumulate方法的具体用法?Java JSONObject.accumulate怎么用?Java JSONObject.accumulate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.accumulate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertUser
import org.json.JSONObject; //导入方法依赖的package包/类
public static JSONObject convertUser(){
Realm realm= Realm.getDefaultInstance();
User user=realm.where(User.class).findFirst();
try {
JSONObject jUser=new JSONObject();
jUser.accumulate("id",user.getId());
jUser.accumulate("token",user.getToken());
jUser.accumulate("lessThan",user.getLessThan());
jUser.accumulate("greaterThan",user.getGreaterThan());
jUser.accumulate("lastseen",user.getLastSeen());
jUser.accumulate("registered",user.getDateRegistered());
jUser.accumulate("userJsonObj",user.getUserJsonObj());
return jUser;
}catch (Exception e){
e.printStackTrace();
}finally {
realm.close();
}
return new JSONObject();
}
示例2: handleGetProgress
import org.json.JSONObject; //导入方法依赖的package包/类
String handleGetProgress(Request req, Response res) {
String url = req.queryMap( "url" ).value();
Optional<ScrapeJob> optJob = MAN.getJob(url);
if ( optJob.isPresent() ) {
ScrapeJob job = optJob.get();
JSONObject response = new JSONObject();
res.type("application/json");
response.accumulate( "finished", job.isJobDone() );
response.accumulate( "done", job.getNumDone() );
response.accumulate( "total", job.getTotal() );
response.accumulate( "layer", job.getName() );
response.accumulate( "failed", job.isFailed() );
if(job.isFailed()) {
response.accumulate( "errorMessage", job.getFailMessage() );
}
return response.toString();
} else {
return NO_JOB_FOUND_MESSAGE;
}
}
示例3: addFilter
import org.json.JSONObject; //导入方法依赖的package包/类
private boolean addFilter(FilterRule filterRule, boolean overwrite) {
try {
JSONObject data = FilterRule.loadSavedFilterRules(this, overwrite);
if (getIntent().getBooleanExtra("modify", false))
data.getJSONArray("rules").put(getIntent().getIntExtra("index", 0), filterRule.toJSONObject());
else
data.accumulate("rules", filterRule.toJSONObject());
FilterRule.saveRules(this, data);
return false;
} catch (Exception e) {
e.printStackTrace();
if (overwrite)
new AlertDialog.Builder(this)
.setTitle(R.string.error_write_file)
.setMessage(getString(R.string.error_saving_filter_rule, e.getMessage()))
.setNeutralButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.show();
return true;
}
}
示例4: addIdentity
import org.json.JSONObject; //导入方法依赖的package包/类
private boolean addIdentity(SSHIdentity identity, boolean overwrite) {
try {
JSONObject data = SSHIdentity.loadSavedIdentities(this, overwrite);
if (getIntent().getBooleanExtra("modify", false))
data.getJSONArray("identities").put(getIntent().getIntExtra("index", 0), identity.toJSONObject());
else
data.accumulate("identities", identity.toJSONObject());
SSHIdentity.saveIdentities(this, data);
return false;
} catch (Exception e) {
e.printStackTrace();
if (overwrite)
new AlertDialog.Builder(this)
.setTitle(R.string.error_write_file)
.setMessage(getString(R.string.error_saving_identity, e.getMessage()))
.setNeutralButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.show();
return true;
}
}
示例5: Register
import org.json.JSONObject; //导入方法依赖的package包/类
public boolean Register(String nick, String email, String password, Intent intent) throws JSONException, IOException {
JSONObject jsonObject = new JSONObject();
// jsonObject.accumulate("client_id",context.getString(R.string.clientid));
// jsonObject.accumulate("client_secret", context.getString(R.string.clientsecret));
// jsonObject.accumulate("grant_type", "password");
jsonObject.accumulate("email", email);
jsonObject.accumulate("password", password);
jsonObject.accumulate("first_name",nick);
String json = jsonObject.toString();
Log.d("mesaj"," "+json);
con.getOutputStream().write(json.getBytes());
if(con.getResponseCode()<300){
JSONObject finalResuslt = response(con);
Log.d("response","register "+finalResuslt);
preferencesShared.putString("accesstoken",finalResuslt.getString("access_token"));
preferencesShared.putString("refreshToken",finalResuslt.getString("refresh_token"));
preferencesShared.putLong("timeout", (System.currentTimeMillis() +((finalResuslt.getLong("expires_in") - 100) * 1000)));
preferencesShared.putString("username", finalResuslt.getString("username"));
preferencesShared.commit();
con.disconnect();
context.startActivity(intent);
context.finish();
return true;
}
else{
InputStream stream = con.getErrorStream();
BufferedReader br = new BufferedReader(new InputStreamReader(stream));
String line;
StringBuilder str = new StringBuilder();
while((line = br.readLine())!=null){
str.append(line).append("\n");
}
Log.d("error", " " + con.getResponseCode() + " mes " + con.getResponseMessage()+" fc " + str.toString());
Toast.makeText(context, str.toString(), Toast.LENGTH_LONG).show();
}
con.disconnect();
return false;
}
示例6: getJsonRequest
import org.json.JSONObject; //导入方法依赖的package包/类
private static JSONObject getJsonRequest(Object params, Session appSession) throws JSONException {
if (params == null) {
return new JSONObject();
}
HashMap<String, Object> requestParams;
if (params instanceof HashMap) {
requestParams = (HashMap<String, Object>) params;
} else {
return new JSONObject();
}
// add parameter node
final Iterator<String> keySet = requestParams.keySet().iterator();
JSONObject jsonParams = new JSONObject();
try {
while (keySet.hasNext()) {
final String key = keySet.next();
Object val = requestParams.get(key);
if (val == null) {
val = "";
}
if (val instanceof String || val instanceof Number) {
jsonParams.accumulate(key, val);
} else if (val instanceof List<?>) {
jsonParams.accumulate(key, getJSONArray((List<?>) val).toString());
} else {
jsonParams.accumulate(key, getJSONObject(val).toString());
}
}
LogUtils.i("请求数据包参数:" + jsonParams.toString());
// return new StringEntity(DesUtils.encrypt(jsonParams.toString()), HTTP.UTF_8);
return jsonParams;
} catch (Exception e) {
e.printStackTrace();
return new JSONObject();
}
}
示例7: connectLogin
import org.json.JSONObject; //导入方法依赖的package包/类
public boolean connectLogin(String user,String password) throws JSONException, IOException {
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("client_id",context.getString(R.string.clientid));
jsonObject.accumulate("client_secret", context.getString(R.string.clientsecret));
jsonObject.accumulate("grant_type", "password");
jsonObject.accumulate("username", user);
jsonObject.accumulate("password", password);
String json = jsonObject.toString();
con.getOutputStream().write(json.getBytes());
Log.d("intra"," "+con.getResponseMessage());
if(con.getResponseCode()<300){
JSONObject finalResuslt = response(con);
preferencesShared.putString("accesstoken",finalResuslt.getString("access_token"));
preferencesShared.putString("refreshToken",finalResuslt.getString("refresh_token"));
preferencesShared.putLong("timeout", (System.currentTimeMillis() +((finalResuslt.getLong("expires_in") - 1000) * 1000)));
preferencesShared.putString("username", user);
preferencesShared.commit();
con.disconnect();
return true;
}
else{
Log.d("error", " " + con.getResponseCode() + " mes " + con.getResponseMessage() + con.getContentEncoding());
Toast.makeText(context, "User Name Or Password is Wrong!", Toast.LENGTH_LONG).show();
}
Log.d("raspuns "+con.getResponseCode(),"sagg");
con.disconnect();
return false;
}
示例8: refresh
import org.json.JSONObject; //导入方法依赖的package包/类
public boolean refresh() throws JSONException, IOException {
long timeout = preferencesShared.getLong("timeout",0);
if(timeout > System.currentTimeMillis()){
return true;
}else {
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("client_id", context.getString(R.string.clientid));
jsonObject.accumulate("client_secret", context.getString(R.string.clientsecret));
jsonObject.accumulate("grant_type", "refresh_token");
jsonObject.accumulate("username", preferencesShared.getString("username", ""));
jsonObject.accumulate("refresh_token", preferencesShared.getString("refreshToken", ""));
String json = jsonObject.toString();
con.getOutputStream().write(json.getBytes());
Log.d("intra"," "+con.getResponseMessage());
if (con.getResponseCode() < 300) {
JSONObject finalResuslt = response(con);
preferencesShared.putString("accesstoken", finalResuslt.getString("access_token"));
preferencesShared.putString("refreshToken", finalResuslt.getString("refresh_token"));
preferencesShared.putLong("timeout", (System.currentTimeMillis() + ((finalResuslt.getLong("expires_in") - 100) * 1000)));
preferencesShared.commit();
con.disconnect();
return true;
} else {
con.disconnect();
return false;
}
}
}
示例9: sendMessage
import org.json.JSONObject; //导入方法依赖的package包/类
public void sendMessage(String message){
final Preferences pref = Gdx.app.getPreferences("informationLog");
String acces = pref.getString("accesstoken");
JSONObject json = new JSONObject();
json.accumulate("txt",message);
HttpRequestBuilder builder = new HttpRequestBuilder();
Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + join).build();
request.setHeader("Authorization", "Bearer " + acces);
request.setHeader("Content-type", "application/json");
request.setContent(json.toString());
Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() {
@Override
public void handleHttpResponse(Net.HttpResponse httpResponse) {
//Gdx.app.log("response :"+httpResponse.getStatus().getStatusCode(),"message "+httpResponse.getResultAsString());
}
@Override
public void failed(Throwable t) {
//Gdx.app.log("response :","failed "+t);
}
@Override
public void cancelled() {
//Gdx.app.log("response :","cancel ");
}
});
}
示例10: sendMessage
import org.json.JSONObject; //导入方法依赖的package包/类
public void sendMessage(String message){
final Preferences pref = Gdx.app.getPreferences("informationLog");
String acces = pref.getString("accesstoken");
JSONObject json = new JSONObject();
json.accumulate("txt",message);
HttpRequestBuilder builder = new HttpRequestBuilder();
Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + join).build();
request.setHeader("Authorization", "Bearer " + acces);
request.setHeader("Content-type", "application/json");
request.setContent(json.toString());
Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() {
@Override
public void handleHttpResponse(Net.HttpResponse httpResponse) {
// Gdx.app.log("response :"+httpResponse.getStatus().getStatusCode(),"message "+httpResponse.getResultAsString());
}
@Override
public void failed(Throwable t) {
//Gdx.app.log("response :","failed "+t);
}
@Override
public void cancelled() {
//Gdx.app.log("response :","cancel ");
}
});
}
示例11: makeRequest
import org.json.JSONObject; //导入方法依赖的package包/类
public void makeRequest(int id){
final Preferences pref = Gdx.app.getPreferences("informationLog");
String acces = pref.getString("accesstoken");
JSONObject json = new JSONObject();
json.accumulate("faction_id",id);
HttpRequestBuilder builder = new HttpRequestBuilder();
Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + join).build();
request.setHeader("Authorization", "Bearer " + acces);
request.setHeader("Content-type", "application/json");
request.setContent(json.toString());
Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() {
@Override
public void handleHttpResponse(Net.HttpResponse httpResponse) {
//Gdx.app.log("response :","message "+httpResponse.getResultAsString());
}
@Override
public void failed(Throwable t) {
//Gdx.app.log("response :","failed ");
}
@Override
public void cancelled() {
//Gdx.app.log("response :","cancel ");
}
});
}
示例12: makeRequest
import org.json.JSONObject; //导入方法依赖的package包/类
public void makeRequest(int id, final ScreenCombat screenCombat){
final Preferences pref = Gdx.app.getPreferences("informationLog");
final String acces = pref.getString("accesstoken");
JSONObject parameters = new JSONObject();
parameters.accumulate("enklave_combat_id",id);
HttpRequestBuilder builder = new HttpRequestBuilder();
Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + prof).build();
request.setHeader("Authorization", "Bearer " + acces);
request.setHeader("Content-type", "application/json");
request.setContent(parameters.toString());
Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() {
@Override
public void handleHttpResponse(Net.HttpResponse httpResponse) {
screenCombat.showCover();
Gdx.app.log("raspuns hit Enklave cod :"+httpResponse.getStatus().getStatusCode()," message : "+httpResponse.getResultAsString());
}
@Override
public void failed(Throwable t) {
}
@Override
public void cancelled() {
}
});
}
示例13: makeRequest
import org.json.JSONObject; //导入方法依赖的package包/类
public void makeRequest(int id, final ScreenCombat screenCombat){
final Preferences pref = Gdx.app.getPreferences("informationLog");
final String acces = pref.getString("accesstoken");
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("enklave_id", id);
HttpRequestBuilder builder = new HttpRequestBuilder();
Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + prof).build();
request.setHeader("Authorization", "Bearer " + acces);
request.setHeader("Content-type", "application/json");
request.setContent(jsonObject.toString());
Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() {
@Override
public void handleHttpResponse(Net.HttpResponse httpResponse) {
String res = httpResponse.getResultAsString();
Gdx.app.log("raspuns start code "+httpResponse.getStatus().getStatusCode(),"rasp mess: "+res);
if(httpResponse.getStatus().getStatusCode()<300){
JSONObject j = new JSONObject(res);
informationProfile.getDateUserGame().setEnklaveCombatId(j.getInt("enklave_combatant_id"));
InformationEnklave.getInstance().setCombatId(j.getInt("enklave_combat_id"));
informationProfile.getDateUserGame().setInCombat(true);
}else{
JSONObject json = new JSONObject(res);
if(json.getString("detail").contentEquals("You already joined this combat once"))
InformationProfile.getInstance().getDateUserGame().setEnklaveCombatId(-1);
informationProfile.getDateUserGame().setInCombat(true);
screenCombat.dialogExit(json.getString("detail").substring(0,20)+"\n"+json.getString("detail").substring(21));
}
}
@Override
public void failed(Throwable t) {
Gdx.app.log("error parse data : ","err: "+t);
}
@Override
public void cancelled() {
}
});
}
示例14: makeRequest
import org.json.JSONObject; //导入方法依赖的package包/类
public void makeRequest(int id){
final Preferences pref = Gdx.app.getPreferences("informationLog");
final String acces = pref.getString("accesstoken");
JSONObject parameters = new JSONObject();
parameters.accumulate("enklave_id",id);
HttpRequestBuilder builder = new HttpRequestBuilder();
Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + prof).build();
request.setHeader("Authorization", "Bearer " + acces);
request.setHeader("Content-type", "application/json");
request.setContent(parameters.toString());
Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() {
@Override
public void handleHttpResponse(Net.HttpResponse httpResponse) {
Gdx.app.log("raspuns unsubscribe cod :"," message : "+httpResponse.getResultAsString());
}
@Override
public void failed(Throwable t) {
}
@Override
public void cancelled() {
}
});
}
示例15: makeRequest
import org.json.JSONObject; //导入方法依赖的package包/类
public void makeRequest(int id, final ScreenCombat screenCombat){
final Preferences pref = Gdx.app.getPreferences("informationLog");
final String acces = pref.getString("accesstoken");
JSONObject parameters = new JSONObject();
parameters.accumulate("enklave_combatant_id",id);
HttpRequestBuilder builder = new HttpRequestBuilder();
Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + prof).build();
request.setHeader("Authorization", "Bearer " + acces);
request.setHeader("Content-type", "application/json");
request.setContent(parameters.toString());
Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() {
@Override
public void handleHttpResponse(Net.HttpResponse httpResponse) {
screenCombat.showCover();
Gdx.app.log("raspuns hit user cod :"+httpResponse.getStatus().getStatusCode()," message : "+httpResponse.getResultAsString());
}
@Override
public void failed(Throwable t) {
}
@Override
public void cancelled() {
}
});
}