16,473
社区成员
发帖
与我相关
我的任务
分享
int Impl::convert_json(const char* result, std::string& w)
{
int ret = 0;
u_int word_len = 0;
std::vector<std::string> resultList2;
Json::Reader reader;
Json::Value root;
u_int wave_len = 0;
Json::FastWriter writer;
if(reader.parse(result, root, false))
{
int sn =root["sn"].asInt();
std::cout << "sn="<< sn <<std::endl;
string w =root["ws"]["cw"]["w"].asString();
std::cout << "w="<< w <<std::endl;
Json::Value ws_result = root.get("ws", Json::Value::null);
if (!ws_result.isArray())
{
printf("convert_json | ws_result is not array\n");
return -1;
}
for(Json::Value::iterator it = ws_result.begin(); it != ws_result.end(); it++)
{
Json::Value ws_cw_result = (*it).get("cw", Json::Value::null);
for(Json::Value::iterator it = ws_cw_result.begin(); it != ws_cw_result.end(); it++)
{
Json::Value ws_cw_w_result = (*it).get("w", Json::Value::null);
std::cout << ws_cw_w_result<<std::endl;
std::string strWrite = writer.write(ws_cw_w_result);
/*std::ofstream ofs;
ofs.open("2.txt",ios::app);
ofs << strWrite;
ofs.close();*/
FILE *fc = fopen("2.txt", "a");
fprintf(fc, "%s", strWrite );
fclose(fc);
}
}
}
return ret;
}
void CrecordDlg::OnBnClickedRecognition()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CFile sf;
CString str("");
sf.Open(_T("2.TXT"), CFile::modeRead);
DWORD size3 = sf.GetLength();
//char resultbuf[1000];
char *resultbuf;
resultbuf = new char[size3+1];
memset(resultbuf,0,size3+1);
sf.Read(resultbuf,size3);
int len = size3+1;
int unicodeLen = ::MultiByteToWideChar( CP_UTF8,
0,
resultbuf,
-1,
NULL,
0 );
wchar_t * pUnicode;
pUnicode = new wchar_t[unicodeLen+1];
memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));
::MultiByteToWideChar( CP_UTF8,
0,
resultbuf,
-1,
(LPWSTR)pUnicode,
unicodeLen );
CString rt;
rt = ( wchar_t* )pUnicode;
delete pUnicode;
delete[] resultbuf;
//delete[] audio_buf;
//audio_buf=NULL;
m_editresult = rt;
int n = m_editresult.Remove( '"' );
// 根据各变量的值更新相应的控件。
UpdateData(FALSE);
}