json - 在序列化 JSON 的末尾获取一个 INT
问题描述
所以我正在更新这个,因为我已经得到了 JSON OUT 但是 JSON 后面跟着一个 INT
{“函数”:“时间报告”,“值”:545028}41
#include <ArduinoJson.h>
char owner[] = "";
const int capacity = JSON_OBJECT_SIZE(2);
DynamicJsonDocument doc(capacity);
void setup() {
Serial.begin(115200);
}
void loop() {
doc["function"]="timereport";
doc["values"]=millis();
Serial.println(serializeJson(doc, Serial));
delay(5000);
}
第二次尝试:(帖子最后仍然有INT)
char json_string[256];
http.begin("http://192.168.1.103:2000/hydroapi"); //Specify destination for HTTP request
http.addHeader("Content-Type","application/json");
doc["function"]="timereport";
doc["values"]=millis();
serializeJson(doc, json_string);
int httpResponseCode = http.POST(json_string); //Send the actual POST request
http.end();
解决方案
调用serializeJson
将 json 打印到Serial
(因为这是您传入的流)并返回打印的字节数,然后您将使用Serial.println
. 删除调用以Serial.println
避免打印字节数,只需调用serializeJson(doc, Serial);
推荐阅读
- r - 如何根据另一个数据集中的重复值重新编码值
- javascript - label元素的for属性的值一定是非隐藏表单控件的ID?
- c# - 使用 C# 获取打印机状态
- javascript - 为什么 Ember-Cli 3.14 会抛出 ESLint No-New-Mixin 错误
- vue.js - 如何通过 vue.js 中的道具传递图像 url
- javascript - 用第二个数组中的匹配属性替换一个数组中的值
- java - Glassfish 服务器和 ActiveMQ 的问题:对等方没有发送他的有线格式
- c - 数组中的 DB2 C UDF 参数
- python - 如何对以下表达式进行数值积分?
- javascript - JavaScript 承诺?