说下每个步骤稍微说一下我当初遇到的难题:
把“部分1”走通后,我确信此种方案可行。官网上有详细的教程http://www.cocos.com/doc/article/index?type=cocos2d-x&url=/doc/cocos-docs-master/manual/framework/native/v3/httpclient/zh.md
“部分2” 确定我可以提取从WebService获取的信息,头文件引用这两个就行了
#include “tinyxml.h”
#include “tinystr.h”
但其他的cpp文件也是必要的。
不知道正确的使用方法是怎样的,我的方法看起来就挺山寨的,大家就仅供参考吧,下面是回调函数中的代码
void HttpManage::getCardCompleted(HttpClient *sender, HttpResponse *response)
{
std::vector<char> *buffer = response->getResponseData();
bool b = response->isSucceed();
if (!b)
{
getCard();
return;
}
std::string a = "";
for (unsigned int i = 0; i < buffer->size(); i++)
{
a += (*buffer)*;
}
const char *p = a.c_str();
TiXmlDocument *spXmlDoc = new TiXmlDocument();
spXmlDoc->Parse(p);
TiXmlNode* pNode = NULL;
TiXmlElement *spElement = NULL;
const char * szXmlVaule = NULL;
ConstClass::MYCARD2_TYPE = std::atoi(spXmlDoc->FirstChild("int")->ToElement()->GetText());
HttpData::getCardHandler();
}
*
由于这个WebService得方法返回值是个整形,所以直接FristChild("int")就可以了,如果返回值是个自定义的类,那么前面都一样,提取的地方改成这样:
ConstClass::P_ID_FROM = std::atoi(spXmlDoc->FirstChild("Result")->FirstChildElement("pIDfrom")->ToElement()->GetText());
ConstClass::P_ID_TO = std::atoi(spXmlDoc->FirstChild("Result")->FirstChildElement("pIDto")->ToElement()->GetText());
ConstClass::TYPE_FROM1 = std::atoi(spXmlDoc->FirstChild("Result")->FirstChildElement("typeFrom1")->ToElement()->GetText());
ConstClass::TYPE_FROM2 = std::atoi(spXmlDoc->FirstChild("Result")->FirstChildElement("typeFrom2")->ToElement()->GetText());
ConstClass::GESS_TYPE = std::atoi(spXmlDoc->FirstChild("Result")->FirstChildElement("typeGess")->ToElement()->GetText());
ConstClass::TYPE_TO = std::atoi(spXmlDoc->FirstChild("Result")->FirstChildElement("typeTo")->ToElement()->GetText());