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