嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
Android客户端用Json与Asp.Net服务器交互信息
JSONArray userArray = new JSONArray(); for(UserInfo ui : lUser) { JSONObject userObject = new JSONObject(); userObject.put("Id", ui.getId()); userObject.put("Username", ui.getUsername()); JSONArray hobby = new JSONArray(); for(String str : ui.getHobby()) hobby.put(str); userObject.put("Hobby", hobby); userObject.put("Birthday", ui.getBirthday()); userArray.put(userObject); } List<NameValuePair> pair = new ArrayList<NameValuePair>(); pair.add(new BasicNameValuePair("type", "up")); pair.add(new BasicNameValuePair("json", userArray.toString())); HttpPost post = new HttpPost(URL); post.setEntity(new UrlEncodedFormEntity(pair, "utf-8")); HttpResponse resp = new DefaultHttpClient().execute(post); if(resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { Toast.makeText(mContext, "上传成功!", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(mContext, "与服务器通信失败,错误代码:" resp.getStatusLine().getStatusCode(), Toast.LENGTH_SHORT).show(); } }