static int getCharElement(const char *pSrc, const char *pTarget, char *pResult)
{
char * pSearchPoint = NULL;
int i = 0;
if (pSrc == NULL || pResult == NULL)
{
return 0;
}
pSearchPoint = strstr(pSrc, pTarget);
if (pSearchPoint != NULL)
{
pSearchPoint += (strlen(pTarget) + 3);
while (pSearchPoint[i] != '"')
{
pResult[i] = pSearchPoint[i];
i++;
}
}
else
{
return 0;
}
pResult[i] = '\0';
return 1;
}
实例:从{ “returnCode”:“200”}中获取returnCode,可以按如下方法调用:
char result[32] = {0};
getCharElement("{ “returnCode”:“200”}", “returnCode”, result);