服務端返回json給客戶端 如何用post方法向服務器發(fā)送一個json類型的字符串?
如何用post方法向服務器發(fā)送一個json類型的字符串?1. 程序設計語言//---1。Httppost request=new Httppost(URL)//封裝JSON對象jsonobject p
如何用post方法向服務器發(fā)送一個json類型的字符串?
1. 程序設計語言//---1。Httppost request=new Httppost(URL)//封裝JSON對象jsonobject param=new jsonobject()參數輸入(“name”,“rarnu”)參數輸入(“密碼”,“123456”//bind to request entry stringentity SE=new stringentity(參數toString()) 請求.setEntity(SE)//發(fā)送請求httpresponse httpresponse=New defaulthttpclient()。Execute(request)//獲取響應字符串,也是以JSON格式保存的數據字符串retsrc=EntityUtils.toString文件( httpResponse.getEntity())//生成一個JSON對象。Jsonobject result=新Jsonobject(retsrc)字符串標記=結果.get(“token”)2、jQuery$.post(”getUserMessage.ashx?t=“數學.隨機(),{用戶名:txtUserName.val文件(),用戶密碼:txtPassWord.val文件()},函數(JSON){if(JSON){//return JSON data processing},“JSON”)