如何在arduino的char数组中放置变量?

时间:2019-03-03 10:18:56

标签: arrays json arduino char

这是我的代码。

$ ./bin/read_multiline_pairs dat/pairsbinline.txt
a: 010101000001010111110100101010000000111100000000000011110000
b: 0000011111000001000110101010100111110001

a: 0000001111111111110000111111111111000
b: 00000001111001010101

我想像这样将变量放置在json数组中

$ valgrind ./bin/read_multiline_pairs dat/pairsbinline.txt
==14257== Memcheck, a memory error detector
==14257== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==14257== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==14257== Command: ./bin/read_multiline_pairs dat/pairsbinline.txt
==14257==
a: 010101000001010111110100101010000000111100000000000011110000
b: 0000011111000001000110101010100111110001

a: 0000001111111111110000111111111111000
b: 00000001111001010101

==14257==
==14257== HEAP SUMMARY:
==14257==     in use at exit: 0 bytes in 0 blocks
==14257==   total heap usage: 8 allocs, 8 frees, 872 bytes allocated
==14257==
==14257== All heap blocks were freed -- no leaks are possible
==14257==
==14257== For counts of detected and suppressed errors, rerun with: -v
==14257== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

variable1和variable2是char类型,我想读取传感器数据和赋值,然后将这些变量放置到json char数组中以创建json对象。 谁能举个例子将变量放置在char数组中? 谢谢。

1 个答案:

答案 0 :(得分:0)

您可以像这样将json定义为字符串

String json = "{\"ID\":\"01\",\"Value\":[\"{" + variable1 + "}\",\{" + variable2 + "}\"]}";

或者您可以像这样添加到字符串数组

char *json[] = {
           "{\"ID\":\"01\",\"Value\":[\"{" + variable1 + "}\",\{" + variable2 + "}\"]}"
        };

您可以查看此Arduino参考leastsq

还可以查看Arduino串联参考here