安卓APP數(shù)據(jù)json方式接口
/**
* 訪問數(shù)據(jù)庫并返回JSON數(shù)據(jù)字符串
*
* @param params 向服務(wù)器端傳的參數(shù)
* @param url
* @return
* @throws Exception
*/
public static String doPost(List
throws Exception {
String result = null;
// 獲取HttpClient對象
HttpClient httpClient = new DefaultHttpClient();
// 新建HttpPost對象
HttpPost httpPost = new HttpPost(url);
if (params != null) {
// 設(shè)置字符集
HttpEntity entity = new UrlEncodedFormEntity(params, HTTP.UTF_8);
// 設(shè)置參數(shù)實體
httpPost.setEntity(entity);
}
/*// 連接超時
httpClient.getParams().setParameter(
CoreConnectionPNames.CONNECTION_TIMEOUT, 3000);
// 請求超時
httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,
3000);*/
// 獲取HttpResponse實例
HttpResponse httpResp = httpClient.execute(httpPost);
// 判斷是夠請求成功
if (httpResp.getStatusLine().getStatusCode() == 200) {
// 獲取返回的數(shù)據(jù)
result = EntityUtils.toString(httpResp.getEntity(), "UTF-8");
} else {
Log.i("HttpPost", "HttpPost方式請求失敗");
}
return result;
}
其次Json數(shù)據(jù)解析:
json數(shù)據(jù): [{"id":"67","biaoTi":"G","logo":"http://www.nuoter.com/wtserver/
resources/upload/13508741845270.png","logoLunbo":"http://www.nuoter.com/
wtserver/resources/upload/13509015004480.jpg","yuanJia":"0","xianJia":"0"},{"id":"64","bi
aoTi":"444","logo":"http://www.nuoter.com/wtserver/resources/upload/13508741704400.png"
"logoLunbo":"http://172.16.1.75:8080/wtserver/resources/upload/13508741738500.png","yuanJia":
"0","xianJia":"0"},{"id":"62","biaoTi":"jhadasd","logo":"http://www.nuoter.com/wtserver/resources/uplo
ad/13508741500450.png","logoLunbo":"http://172.16.1.75:8080/wtserver/resources/upload/13508741557450.png",
"yuanJia":"1","xianJia":"0"}]
推薦文章
2025-01-18
2024-11-28
2024-11-09
2024-10-25
2024-06-25
2024-01-04
2023-11-06
2023-10-30
2023-10-13
2023-10-10
穩(wěn)定
產(chǎn)品高可用性高并發(fā)貼心
項目群及時溝通專業(yè)
產(chǎn)品經(jīng)理1v1支持快速
MVP模式小步快跑承諾
我們選擇聲譽堅持
10年專注高端品質(zhì)開發(fā)聯(lián)系我們
友情鏈接: