前端之家收集整理的这篇文章主要介绍了
JSONObject 转换为 request 参数,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
private String jsonObjToRequestStr(JSONObject json,int length) {
StringBuilder str;
Iterator it;
try {
str = new StringBuilder();
if (length > 0) {
it = json.keys();
while (it.hasNext()) {
String name = it.next().toString();
try {
str.append(name).append("=").append(json.get(name)).append("&");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return str.substring(0,str.length() - 1).toString();
} finally {
json = null;
str = null;
it = null;
}
}