Когда я передаю значение в функцию Json_setValue(h, key, value, valueSize)
, тогда устанавливается только половина строкового значения.
После построения объекта в виде строки используйте:
Json_build(object,cpy_buff,&builtBuffSize);
буфер содержит только половину строки в ключе данных (key2).
Я использую эту библиотеку:
Мой код:
while((ftell(new))<=(fsize-88))
{
for(i=1;i<3;i++)
{
fgets(cpy_buff,sizeof(cpy_buff),new);
strcat(mybuff,cpy_buff);
memset(cpy_buff, 0, sizeof(cpy_buff));
// puts("yes");
}
x=strlen(mybuff);
sprintf(conbuff,"len of my buff %d",x);
puts(conbuff);
// puts(mybuff); //1
sprintf(conbuff,"pointer loc=%d",ftell(new));
// puts(conbuff);
Json_parse(object, mybuff, strlen(mybuff));
sprintf(conbuff,"pos of new after reading buff =%d",ftell(new));
puts(conbuff); //2
Json_getValue(object, key1, &o_value1, &value1_size); // get value of line key in output value buff
Json_getValue(object, key2, &o_value2, &value2_size); //get value of data key in output value buff
//// o_value2 is the data buffer.This is will be used to publish data
Json_setValue(object,key1,&s_value,value1_size);
strcpy(newbuff,o_value2);
puts(newbuff);
Json_setValue(object,key2,&newbuff,value2_size);
Теперь после создания объекта снова cpy
-буфф содержит только (1 января 2017 00:00:00 75 822 96) вместо (1 января 2017 00:00:00 75 822 96 548 85 76 82 93 78 82 64 89 899)
// only half string is present in the cpy_buff////////////////////////////////////////
Json_build(object,cpy_buff,&builtBuffSize);
/////////////////////////////////////////////////////////////////////////////////////////////
puts(cpy_buff);
sprintf(conbuff,"pos of new before writing into file =%d",ftell(new));
puts(conbuff); //3
fseek(new, -x, SEEK_CUR);
sprintf(conbuff,"pos of new after setting to -x =%d",ftell(new));
puts(conbuff);
fwrite(cpy_buff,1,strlen(cpy_buff),new);
fputs("\r\n",new);
sprintf(conbuff,"pos of new after writing into file =%d",ftell(new));
puts(conbuff);
fseek(new,0, SEEK_CUR);
sprintf(conbuff,"pos of new after setting to 0 =%d",ftell(new));
puts(conbuff);
memset(mybuff, 0, sizeof(mybuff));
}
fclose(new);
/* Close both inputfile[] and outputfile[] */
strcpy(conbuff,"akjsdabsdas");
puts(conbuff);
/* Stopping the SDCard */
SDFatFS_close(sdfatfsHandle);
Display_printf(display, 0, 0, "Drive %u unmounted\n", DRIVE_NUM);
return (NULL);
}