在Json_setValue()函数中,仅将字符串的一半值设置为键

时间:2019-06-24 18:05:40

标签: c json

当我在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 -buff仅包含(2017年1月1日00:00:00 75 822 96)而不是((2017年1月1日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);
}

0 个答案:

没有答案