读取单条json数据代码

来源:互联网 发布:javascript初级视频 编辑:程序博客网 时间:2024/05/16 10:01

public class HD_zan_post {
 /**
  *
  * @param url 网上的地址
  * @param login_user 传递的用户名
  * @param now_userid 传递的用户id
  * @param id 这个是对应哪个活动的id
  * @param action 传递固定的参数
  * @param type 传递固定的参数类型
  * @return
  * @throws JSONException
  * @throws ParseException
  * @throws IOException
  */
 public static String huodongzan_post(String url, String login_user,
   String now_userid, String id, String action, String type
) throws JSONException, ParseException, IOException {    //都是自己定义的
  // TODO Auto-generated method stub
  String back = Constz.back;
  url = Constz.IPAddress + url;

  // System.out.println("发布活动网址  url  " + url);

  HttpClient httpClient = new DefaultHttpClient();
  HttpPost httpPost = new HttpPost(url);
  JSONObject jsonObject = new JSONObject();
  jsonObject.put("login_user", login_user);
  jsonObject.put("now_userid", now_userid);
  jsonObject.put("action", action);
  jsonObject.put("id", id);
  jsonObject.put("type", type);
  
  List<BasicNameValuePair> listPairs = new ArrayList<BasicNameValuePair>();

  listPairs.add(new BasicNameValuePair("json", jsonObject.toString()));

  System.out.println("listPairs 活动点赞 " + listPairs.toString());
  httpPost.setEntity(new UrlEncodedFormEntity(listPairs, "utf-8"));
  HttpResponse response = httpClient.execute(httpPost);

  int code = response.getStatusLine().getStatusCode();
   System.out.println("code  活动点赞 " + code);

  if (code == 200) {
   HttpEntity entity = response.getEntity();
   back = EntityUtils.toString(entity, "utf-8");
    System.out.println("活动点赞    " + back);
  }
  return back;

 }
}

 

PS: 然后在需要用到的activity页面写入这个类的方法名,并传递相应的参数

 

 

0 0
原创粉丝点击