c++、webServices、gsoap、tinyxml、iconv

c++、webServices、gsoap、tinyxml、iconv

大家好,又见面了,我是全栈君。

  背景解释。编程语言c++,实际项目上会用MFC,数据下载方式为gsoap,拉下来的数据类型为string,用tinyxml对拉下来的string类型进行解析,其中的中文字符都是乱码,用iconv来解码(from utf-8 to GBK)。

//main.cpp

 1 #include "AppServiceSoap.nsmap"  2 #include "soapAppServiceSoapProxy.h"  3 #include "iconv.h"  4 #include "tinystr.h"  5 #include "tinyxml.h"  6  7 using namespace std;  8  9 #define OUTPUT_LEN 2048 10 #define FIELD_LEN 16 11 12 int conv_charset(const char *dest, const char *src, char *input, size_t ilen, char *output, size_t olen) 13 { 14 iconv_t conv = iconv_open(dest, src); 15 if (conv == (iconv_t)-1) 16 return -1; 17 memset(output, 0, olen); 18 19 if (iconv(conv, (const char **)&input, &ilen, &output, &olen)) 20 return -1; 21  iconv_close(conv); 22 return 0; 23 } 24 25 int main() 26 { 27  AppServiceSoapProxy webservice; 28  soap_init(webservice.soap); 29  soap_set_mode(webservice.soap, SOAP_C_UTFSTRING); 30 31 _WS1__SampleDataByBarCodeNoXML request = _WS1__SampleDataByBarCodeNoXML(); 32 string tmp = "18010354204"; 33 request.sSampleBarCodeNo = &tmp; 34 35 _WS1__SampleDataByBarCodeNoXMLResponse response = _WS1__SampleDataByBarCodeNoXMLResponse(); 36 37 char *endpoint = NULL; 38 39 int result = webservice.SampleDataByBarCodeNoXML(&request, response); 40 41 if (SOAP_OK == result) 42  { 43 //int element_counter = response.SampleDataByBarCodeNoXMLResult->__sizestring; 44 cout << *response.SampleDataByBarCodeNoXMLResult <<endl; 45 cout << "--------------------开始解码--------------------" << endl; 46 47 TiXmlDocument* myDocument = new TiXmlDocument(); 48 myDocument->Parse((*(response.SampleDataByBarCodeNoXMLResult)).c_str(), 0, TIXML_ENCODING_UTF8); 49 TiXmlElement* rootElement = myDocument->RootElement(); 50 TiXmlElement* studentsElement = rootElement->FirstChildElement(); 51 studentsElement = studentsElement->FirstChildElement(); 52 53 while (studentsElement) 54  { 55 cout << studentsElement->Value() << ":"; 56 57 if (studentsElement->GetText()) 58  { 59 int ilen = strlen(studentsElement->GetText()); 60 int olen = ilen * 2; 61 char *output = (char *)malloc(sizeof(char) * olen); 62 char* input = nullptr; //初始化char*类型 63 64 input = const_cast<char*>(studentsElement->GetText()); //const char*类型转char*类型 65 66 conv_charset("GBK", "UTF-8", input, ilen, output, olen); 67 cout << output << endl; 68  } 69 else 70  { 71 cout << "(此项无内容)" << endl; 72  } 73 74 studentsElement->utf8ByteTable; 75 76 //迭代下一个 77 studentsElement = studentsElement->NextSiblingElement(); 78  } 79  } 80 //结束了 81  soap_destroy(webservice.soap); 82  soap_end(webservice.soap); 83  soap_done(webservice.soap); 84 85 cout << "---------------------finish-----------------------" << endl; 86 cin.get(); 87 return 0; 88 }

项目的目录结构。

c++、webServices、gsoap、tinyxml、iconv

主要分成3部分。

1、gsoap。

先做soap,这个参考上一篇。

2、tinyxml。

这个比较简单。

3、iconv.h,iconv.lib

这个好难。我都是用别人编译好的。

参考:https://www.cnblogs.com/tangxin-blog/p/5608751.html。

转载于:https://www.cnblogs.com/wuzhenyang/p/8523740.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/107671.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • 透视投影矩阵_透视投影矩阵推导知乎

    透视投影矩阵_透视投影矩阵推导知乎透视投影矩阵TheOpenGLPerspectiveProjectionMatrix关于透视投影矩阵的使用BuildingaBasicPerspectiveProjectionMatrixTheOpenGLPerspectiveProjectionMatrix首先,重要的是要记住OpenGL中的矩阵是使用列主顺序(而不是行主顺序)定义的。在所有的OpenGL书籍和参考文献中,OpenGL中使用的透视投影矩阵定义为:我们可以简单地转置矩阵,我们可以得到下面的以行向量为顺序的

  • Spring整合MyBatis——超详细

    Spring整合MyBatis——超详细Spring整合MyBatis——超详细一、Spring整合MyBatis的三个关键点二、整合步骤1、创建一个Maven项目2、在pom.xml文件中添加jar包的依赖2、配置MyBatis文件(1)新建一个实体类的包和User实体类(2)编写实体类(3)新建Mapper接口包和UserMapper接口(3)新建jdbc资源文件jdbc-config.properties(4)新建mybatis配置文件mybatis.xml(5)新建logj4j的日志配置文件log4j.properties

  • Visual Studio Code(VSCODE)语言设置为中文

    Visual Studio Code(VSCODE)语言设置为中文

  • Linux xsync命令脚本

    Linux xsync命令脚本在/bin/目录下创建xsync脚本如下:#!/bin/bash#1.判断参数个数if[$#-lt1]thenechoNotEnoughArguement!exit;fi#2.遍历集群所有机器forhostinmasternode1node2doecho====================$host====================#3.遍历所有目录,挨个发送forfilein$@do#4…

  • CRTMP视频直播服务器部署及测试

    CRTMP视频直播服务器部署及测试一、搭建CRTMP视频直播服务器1、下载CRTMP服务器软件svnco–usernameanonymous–password””https://svn.rtmpd.com/crtmpserver/trunkcrtmpserver2、进入一下目录,

  • 电脑word文档图标变了怎么办_word图标变成白纸

    电脑word文档图标变了怎么办_word图标变成白纸当我们在使用word文档的时候,可能会遇到word文档图标显示异常的情况,那么这个时候我们该怎么办?下面是学习啦小编整理的word文档图标显示异常的解决方法,供您参考。word文档图标显示异常的解决方法一点击“开始”菜单,输入“运行”并搜索。点击“运行”。输入regedit,然后点击确定。双击打开HKEY_CLASSES_ROOT。找到.docx,鼠标右击,选择删除。用同样的方法依次打开HKEY…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号