且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将 HttpEntity 转换为 JSON?

更新时间:2023-02-14 10:29:46

您可以将字符串转换为 json 为:

You can convert string to json as:

try {
        response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();

        if (entity != null) {
           String retSrc = EntityUtils.toString(entity); 
           // parsing JSON
           JSONObject result = new JSONObject(retSrc); //Convert String to JSON Object

             JSONArray tokenList = result.getJSONArray("names");
             JSONObject oj = tokenList.getJSONObject(0);
             String token = oj.getString("name"); 
        }
}
 catch (Exception e) {
  }