Back to project page android-json-http.
The source code is released under:
Apache License
If you think the Android project android-json-http listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.open.jsonhttp.util; //www . j a v a 2s . co m import java.util.HashMap; import org.json.JSONException; import org.json.JSONObject; import android.util.Log; import com.google.gson.Gson; import com.open.jsonhttp.ResponseBean; /** * ?????? * * @author yinghui.hong */ public class ParseUtil { private static final String TAG = ParseUtil.class.getSimpleName(); /** * ?HashMap???Query??? * * @param valueMap * @return */ public static String parseMap2QueryStr(HashMap<String, Object> valueMap) { StringBuilder paramsStr = new StringBuilder(); if (valueMap != null && valueMap.size() > 0) { paramsStr.append("?"); for (String key : valueMap.keySet()) { paramsStr.append(key).append("=").append(valueMap.get(key)) .append("&"); } paramsStr.deleteCharAt(paramsStr.length() - 1); } return paramsStr.toString(); } /** * ?HashMap???JSON???? * * @param valueMap * ???????????????? * @return String JSON??? */ public static String parseMap2JsonStr(HashMap<String, Object> valueMap) { Gson gson = new Gson(); String jsonStr = gson.toJson(valueMap); Log.d(TAG, "????? --- " + jsonStr); return jsonStr; } /** * ???JSON??????? * * @param json * ?????????????JSON??? * @param classOfResponseBean * ResponseBean???? * @return ResponseBean????? * @throws JSONException */ public static ResponseBean parseJson2Obj(String json, Class<? extends ResponseBean> classOfResponseBean) throws JSONException { Log.d(TAG, "?????? --- " + json); JSONObject jsonObject = new JSONObject(json); Gson gson = new Gson(); ResponseBean bean = gson.fromJson(jsonObject.toString(), classOfResponseBean); return bean; } }