遠端介面訪問 Webclient

2021-10-04 20:35:52 字數 1045 閱讀 4377

webclient client = new webclient();//例項化遠端訪問類;

byte data = client.downloaddata("");//位元陣列:是計算機中的通用單元,位元可以通過作業系統轉化為任何物件;

string html = encoding.utf8.getstring(data);//遠端返回的數值後,我們需要將位元陣列轉化為字串;

//將字串轉化為物件;

//使用newtonsoft進行反序列化;newtonsoft提供了乙個特有型別叫jobject

jobject obj = (jobject)jsonconvert.deserializeobject(html);

console.writeline(obj["geocodes"][0]["location"]);

console.writeline(html);

console.readkey();

序列化:將資料轉化為json格式。

資料進行序列化的目的是為了跨平台傳輸,json是一種通用格式。

反序列化:將json格式轉化為程式中的資料型別。

json格式使用上沒有.net中的物件,類好用,所以我們要進行反序列化。

//序列化

string jsonstr = jsonconvert.serializeobject(ds);

//反序列化

//《1》非泛型方法;

jobject obj = (jobject)jsonconvert.deserializeobject(str);

console.writeline(obj["booklist"][0]["book"]);

《2》泛型的使用

student s = jsonconvert.deserializeobject(str);

console.writeline(s.name);

C 帶參訪問介面,WebClient方式

例項化 webclient client new webclient 位址 string path 資料較大的引數 引數轉流 byte bytearray encoding.utf8.getbytes datastr 採取post方式必須加的header,如果改為get方式的話就去掉這句話即可 cl...

httpClient訪問遠端介面工具類

功能 httpclient訪問遠端介面工具類 是否為get方式請求 boolean isget get equalsignorecase requestmethod boolean ispost post equalsignorecase requestmethod boolean isput pu...

mysql 開啟遠端訪問 遠端訪問

select host,user,password from user 查詢使用者遠端訪問相關資訊 用root使用者登陸,然後 grant all privileges on to 建立的使用者名稱 identified by 密碼 flush privileges 重新整理剛才的內容 格式 gra...