資源描述:
《基于c#的詞典接口調(diào)用代碼實例》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在應(yīng)用文檔-天天文庫。
1、基于C#的詞典接口調(diào)用代碼實例接口描述:基于C#的詞典接口調(diào)用代碼實例接口平臺:聚合數(shù)據(jù)usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Net;usingSystem.IO;usingXfrog.Net;usingSystem.Diagnostics;usingSystem.Web;?//----------------------------------//成語詞典調(diào)用示例代碼-聚合數(shù)據(jù)//在線
2、接口文檔:http://www.juhe.cn/docs/157//代碼中JsonObject類下載地址:http://download.csdn.net/download/gcm3206021155665/7458439//----------------------------------?namespaceConsoleAPI{????classProgram????{????????staticvoidMain(string[]args)????????{????????????stringappkey="******
3、*************";//配置您申請的appkey??????????????????????????//1.根據(jù)成語查詢詳細信息????????????stringurl1="http://v.juhe.cn/chengyu/query";?????????????varparameters1=newDictionary();?????????????parameters1.Add("word","");//填寫需要查詢的漢字,UTF8urlencode編碼????????????par
4、ameters1.Add("key",appkey);//你申請的key????????????parameters1.Add("dtype","");//返回數(shù)據(jù)的格式,xml或json,默認json?????????????stringresult1=sendPost(url1,parameters1,"get");?????????????JsonObjectnewObj1=newJsonObject(result1);????????????StringerrorCode1=newObj1["error_code"].
5、Value;?????????????if(errorCode1=="0")????????????{????????????????Debug.WriteLine("成功");????????????????Debug.WriteLine(newObj1);????????????}????????????else????????????{????????????????//Debug.WriteLine("失敗");????????????????Debug.WriteLine(newObj1["error_code"].
6、Value+":"+newObj1["reason"].Value);????????????}??????????}?????????///????????///Http(GET/POST)????????///????????///請求URL????????///請求參數(shù)????????///請求方法????????/
7、//響應(yīng)內(nèi)容????????staticstringsendPost(stringurl,IDictionaryparameters,stringmethod)????????{????????????if(method.ToLower()=="post")????????????{????????????????HttpWebRequestreq=null;????????????????HttpWebResponsersp=null;???????????
8、?????System.IO.StreamreqStream=null;????????????????try????????????????{????????????????????req=(HttpWebRequest)WebRequest.Create(url);???