bool CIPCamSD::bParseSDListCGI(CString csResponse)
{
CString csStatus,csPath;
int nTotalFileNum(0), nTotalPage(0), nNumOfFilesInList(0), nNumOfPage,nPageSize(0);
Json::Reader jReader;
Json::Value jsonRoot;
bool bOK = jReader.parse(strGetStdString(csResponse), jsonRoot);
Json::ValueType jsonType = jsonRoot.type();
if(jsonRoot.type() == Json::ValueType::objectValue && jsonRoot.type() == Json::ValueType::objectValue)
{
// get string value
if(jsonRoot.get("status", Json::Value()).type() != Json::ValueType::nullValue)
{
csStatus = CString(jsonRoot.get("status", "").asCString());
if(csStatus != _T("ready"))
return false;
}
if(jsonRoot.get("path", Json::Value()).type() != Json::ValueType::nullValue)
{
csPath = CString(jsonRoot.get("path", "").asCString());
}
// get int value, not working so using _ttoi and cstring
if(jsonRoot.get("page", Json::Value()).type() != Json::ValueType::nullValue)
{
nNumOfPage = _ttoi(CString(jsonRoot.get("page", "" ).asCString()));
}
if(jsonRoot.get("pagesize", Json::Value()).type() != Json::ValueType::nullValue)
{
nPageSize = _ttoi(CString(jsonRoot.get("pagesize", "").asCString()));
}
if(jsonRoot.get("total_num", Json::Value()).type() != Json::ValueType::nullValue)
{
nTotalFileNum = _ttoi(CString(jsonRoot.get("total_num", "").asCString()));
}
if(jsonRoot.get("total_page", Json::Value()).type() != Json::ValueType::nullValue)
{
nTotalPage = _ttoi(CString(jsonRoot.get("total_page", "").asCString()));
}
if(jsonRoot.get("num", Json::Value()).type() != Json::ValueType::nullValue)
{
nNumOfFilesInList = _ttoi(CString(jsonRoot.get("num", "").asCString()));
}
// get array value
//"list":[{"name":"20120530_183043_S_C.avi","type":"file","time":"2012-05-30 18:34:10","trigger":"Schedule","size":"104905226"}
if(jsonRoot.get("list", Json::Value()).type() != Json::ValueType::nullValue && jsonRoot.get("list", Json::Value()).type() == Json::ValueType::arrayValue)
{
CString csName,csType,csFileEndTime,csTrigger;
//Json::Value jsonList = jsonRoot.get("list", Json::Value());
Json::Value jsonList = jsonRoot["list"];
for (int index = 0; index < jsonList.size(); index++)
{
CString csName,csType,csTime,csTrigger;
int nSize(0);
if(jsonList[index].type() != Json::ValueType::nullValue)
{
Json::Value jsonListInfo = jsonList[index];
if(jsonListInfo.get("name", Json::Value()).type() != Json::ValueType::nullValue)
{
csName = jsonListInfo.get("name", "").asCString();
}
if(jsonListInfo.get("type", "").type() != Json::ValueType::nullValue)
{
csType = jsonListInfo.get("type", "").asCString();
}
if(jsonListInfo.get("time", Json::Value()).type() != Json::ValueType::nullValue)
{
csFileEndTime = jsonListInfo.get("time", "").asCString();
}
if(jsonListInfo.get("trigger", Json::Value()).type() != Json::ValueType::nullValue)
{
csTrigger = jsonListInfo.get("trigger", "").asCString();
}
if(jsonListInfo.get("size", Json::Value()).type() != Json::ValueType::nullValue)
{
nSize = _ttoi(CString(jsonListInfo.get("size", Json::Value()).asCString()));
}
}
}
}
}
return false;
}