Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, includin...
If you think the Android project pocket4android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (c) 2012-2014 Yu AOKI//www.java2s.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/package com.aokyu.dev.pocket.http;
import org.json.JSONObject;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Set;
publicclass HttpParameters extends HashMap<String, Object> implements MessageBody {
privatestaticfinallong serialVersionUID = -7410515868503883376L;
public HttpParameters() {
super();
}
public String toJson() {
JSONObject jsonObj = new JSONObject(this);
return jsonObj.toString();
}
public String toParameter() {
StringBuilder builder = new StringBuilder();
Set<Entry<String, Object>> entries = entrySet();
boolean first = true;
for (Entry<String, Object> entry : entries) {
if (first) {
first = false;
} else {
builder.append("&");
}
String key = entry.getKey();
Object value = entry.getValue();
builder.append(key);
builder.append("=");
builder.append(value.toString());
}
return builder.toString();
}
public String toEncodedParameter() throws UnsupportedEncodingException {
StringBuilder builder = new StringBuilder();
Set<Entry<String, Object>> entries = entrySet();
boolean first = true;
for (Entry<String, Object> entry : entries) {
if (first) {
first = false;
} else {
builder.append("&");
}
String key = entry.getKey();
Object value = entry.getValue();
builder.append(key);
builder.append("=");
String valueAsString = value.toString();
String encoded = URLEncoder.encode(valueAsString, "UTF-8");
builder.append(encoded);
}
return builder.toString();
}
}