代码片段如下,
typedef map<string ,string> smap;//要转换的目的map
转换函数
string req_update_userprofile_pack_data2(std::string workkey,PyObject *dict_user)
{
Py_ssize_t i, j;
i = 0;
PyObject *key;
PyObject *value;
smap m_profilelist;
while (PyDict_Next(dict_user, &i, &key, &value)) //C++中遍历python的dict对象。此为关键代码
{
char * skey = PyString_AS_STRING(key);
char * svalue = PyString_AS_STRING(value);
string sskey(skey);
string ssvalue(svalue);
if (sskey != "")
{
cout<< ssvalue << endl;
m_profilelist[sskey] = ssvalue;
}
cout << skey << endl;
}
cout <<"get bloadtype"<<m_profilelist["bloodType"] << endl;
{
Py_ssize_t i, j;
i = 0;
PyObject *key;
PyObject *value;
smap m_profilelist;
while (PyDict_Next(dict_user, &i, &key, &value)) //C++中遍历python的dict对象。此为关键代码
{
char * skey = PyString_AS_STRING(key);
char * svalue = PyString_AS_STRING(value);
string sskey(skey);
string ssvalue(svalue);
if (sskey != "")
{
cout<< ssvalue << endl;
m_profilelist[sskey] = ssvalue;
}
cout << skey << endl;
}
cout <<"get bloadtype"<<m_profilelist["bloodType"] << endl;
.....还有其他项目中的代码
return buf;
}
}