一种资源有限单片机处理cJSON数据的方法
一般单片机处理cJSON格式的数据都直接使用cJSON库,但对于Ram较小的单片机,由于资源有限,这并不合适,但我们可以根据cJSON数据的特定格式,使用土方法,直接对字符进行查找裁剪即可
//截取字符串str中字符a与字符b间的子字符串到dest中,Num为从第num个字符a后开始截取
void substr(u8* str,u8* dest,u8 num,char a,char b)
{u16 i=0,j=0,count=0;while(1){if(*(str+i) == a) count++;if(count != num) i++;else break;}while(*(str+i+j+1) != b) j++;memcpy(dest,&str[i+1],j);*(dest+i+j)='\0';
}