小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

delphi2010 調用webservice注意事項

 櫻啊小櫻啊 2014-08-15
    一.delphi做客戶端調用asp.net web service
步驟1. 新建一個vcl工程
步驟2.文件-新建-webservice-WSDLImporter
delphi2010 <wbr>調用webservice注意事項
                                               圖1
 

2.
delphi2010 <wbr>調用webservice注意事項
                圖2

delphi2010 <wbr>調用webservice注意事項
                                       圖3

然后直接next-finish,然后系統(tǒng)會自動生成一個webservice文件,把此文件uses添加到你需要的地方即可,               

3.添加THTTPRIO控件的WSDLLocation屬性(設置), 即webservice wsdl 的url ,然后再選擇port和service屬性,都下拉選擇即可
 
4.由于服務端 其中一個函數(shù)返回的是json數(shù)據(jù),所以要用到TByteArray 數(shù)組,接受字符串一定要用AnsiString,否則用utf8轉換的時候,會有一部分亂碼
 
主要代碼如下
uses   WebService2 ;
procedure TForm1.btn1Click(Sender: TObject);
var
tb: ^TByteArray;
tem,tem1:AnsiString;
P:PChar;
i:Integer;
begin
  tb:=@((htpr1 as ICYZGWebQuery).QueryMemberCertificateInfo('朱成輝','431124199109243419',''))[0];//operaterLogin為接口方法。
  // ShowMessage(IntToStr(tb^));
  // ShowMessage(IntToStr(low(tb^)));
  //ShowMessage(IntToStr(High(tb^)));
  SetString(tem, PAnsiChar(@tb^[0]), high(tb^));
  edt1.Text:=UTF8Decode(tem);
  
   
end;

 

 

二.程序深度分析

返回實際json數(shù)據(jù):

[{"memberName":"朱成輝","sexName":"男","idCardNo":"431124199109243419","education":"大專","companyName":"aaa","telephone":"","address":"湖南省道縣新車鄉(xiāng)新車村3組","zoneName":"湖南省長沙市市轄區(qū)","driversType":"C1","newLicenseDate":"2013-08-14","licenseStartDate":"2013-08-14","licenseDuring":"6年","certificateID":"4301000100014000101","certificateType":"客運駕駛員","newCertificateDate":"2013-08-14","certificateBeginDate":"2014-02-20","certificateEndDate":"2020-02-23","faceImage":null}]

 

TByteArray(實際上就是c++里的無符號char 數(shù)組)數(shù)組接受的數(shù)據(jù):

(91, 123, 34, 109, 101, 109, 98, 101, 114, 78, 97, 109, 101, 34, 58, 34, 230, 156, 177, 230, 136, 144, 232, 190, 137, 34, 44, 34, 115, 101, 120, 78, 97, 109, 101, 34, 58, 34, 231, 148, 183, 34, 44, 34, 105, 100, 67, 97, 114, 100, 78, 111, 34, 58, 34, 52, 51, 49, 49, 50, 52, 49, 57, 57, 49, 48, 57, 50, 52, 51, 52, 49, 57, 34, 44, 34, 101, 100, 117, 99, 97, 116, 105, 111, 110, 34, 58, 34, 229, 164, 167, 228, 184, 147, 34, 44, 34, 99, 111, 109, 112, 97, 110, 121, 78, 97, 109, 101, 34, 58, 34, 97, 97, 97, 34, 44, 34, 116, 101, 108, 101, 112, 104, 111, 110, 101, 34, 58, 34, 34, 44, 34, 97, 100, 100, 114, 101, 115, 115, 34, 58, 34, 230, 185, 150, 229, 141, 151, 231, 156, 129, 233, 129, 147, 229, 142, 191, 230, 150, 176, 232, 189, 166, 228, 185, 161, 230, 150, 176, 232, 189, 166, 230, 157, 145, 51, 231, 187, 132, 34, 44, 34, 122, 111, 110, 101, 78, 97, 109, 101, 34, 58, 34, 230, 185, 150, 229, 141, 151, 231, 156, 129, 233, 149, 191, 230, 178, 153, 229, 184, 130, 229, 184, 130, 232, 190, 150, 229, 140, 186, 34, 44, 34, 100, 114, 105, 118, 101, 114, 115, 84, 121, 112, 101, 34, 58, 34, 67, 49, 34, 44, 34, 110, 101, 119, 76, 105, 99, 101, 110, 115, 101, 68, 97, 116, 101, 34, 58, 34, 50, 48, 49, 51, 45, 48, 56, 45, 49, 52, 34, 44, 34, 108, 105, 99, 101, 110, 115, 101, 83, 116, 97, 114, 116, 68, 97, 116, 101, 34, 58, 34, 50, 48, 49, 51, 45, 48, 56, 45, 49, 52, 34, 44, 34, 108, 105, 99, 101, 110, 115, 101, 68, 117, 114, 105, 110, 103, 34, 58, 34, 54, 229, 185, 180, 34, 44, 34, 99, 101, 114, 116, 105, 102, 105, 99, 97, 116, 101, 73, 68, 34, 58, 34, 52, 51, 48, 49, 48, 48, 48, 49, 48, 48, 48, 49, 52, 48, 48, 48, 49, 48, 49, 34, 44, 34, 99, 101, 114, 116, 105, 102, 105, 99, 97, 116, 101, 84, 121, 112, 101, 34, 58, 34, 229, 174, 162, 232, 191, 144, 233, 169, 190, 233, 169, 182, 229, 145, 152, 34, 44, 34, 110, 101, 119, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 101, 68, 97, 116, 101, 34, 58, 34, 50, 48, 49, 51, 45, 48, 56, 45, 49, 52, 34, 44, 34, 99, 101, 114, 116, 105, 102, 105, 99, 97, 116, 101, 66, 101, 103, 105, 110, ...)

上面?zhèn)鱽硎莡tf8格式數(shù)組(通過查詢第一個漢字朱的ut8編碼可知 230, 156, 177, 十六進制即E69CB1)

那么為什么返回的數(shù)據(jù)一定要用AnsiString接受呢,無意中看到了一篇文章http://hi.baidu.com/whmtorrent/item/bd7073db261171836cce3f1f

它最后說
"值得注意的是,UTF8編碼的字符串一般要將其保存在CHAR(char)型數(shù)組里,而不保存在WCHAR(wchar_t)型數(shù)組里。為什么呢?因為UTF8編碼的字符串每個字符占1-4個字節(jié),有的字符只占1個字節(jié),應該用CHAR型數(shù)組來保存。而WCHAR的話,一個WCHAR就占兩個字節(jié),對于只需要一個字節(jié)的字符,就會出問題。"

我想這也許就是正確答案

 

關于utf8的文章看http://blog.sina.com.cn/s/blog_9e2e84050102uwhv.html


    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多