arduino aJSON library valuefloat always returns 0.00

aJsonObject* sBoard = aJson.createObject(); aJsonObject* sensorType = aJson.createObject(); aJsonObject* sBoard = aJson.createObject(); aJsonObject* sensorType = aJson.createObject(); aJson.addItemToObject(sBoard, "name", aJson.createItem("SensorBoardOne")); aJson.addItemToObject(sBoard, "Sensor", sensorType); aJson.addNumberToObject(sensorType, "ph", 5.33); aJson.addNumberToObject(sensorType, "ec", 880); aJson.addNumberToObject(sensorType, "temp", 74.68); aJsonObject* ph = aJson.getObjectItem(sensorType, "ph"); Serial.println(ph->valuefloat); `Serial.println(ph->valuefloat);` returns 0.00. I have never dealt with C structs before and not sure if I setup the syntax correctly. My json structure seems fairly straight forward; however, I am not sure if I am accessing the correct creatObject() for the ph float value. What should I do to get the proper value of ph? For further information about the aJSON library, please visit: [][1] **EDIT new code:** aJsonObject* sBoard = aJson.createObject(); aJson.addItemToObject(sBoard, "name", aJson.createItem("SensorBoardOne")); aJson.addNumberToObject(sBoard, "ph", 5.33); aJson.addNumberToObject(sBoard, "ec", 880); aJson.addNumberToObject(sBoard, "temp", 74.68); aJsonObject* phValue = aJson.getObjectItem(sBoard, "ph"); char* string = aJson.print(sBoard); if (string != NULL) { Serial.println(string); //prints out: {"name":"SensorBoardOne","ph":5.33000,"ec":880,"temp":74.68000} } Serial.println(phValue->valuefloat); I ended up changing the json structure to more of a simpler structure. I felt there wasn't a need for a another substructure due to the ram shortage of the arduino. After shortening the json structure I was able to successfully get the valuefloat of ph. I am still interested in figuring out the prior issue for future reference. [1]:

以上就是arduino aJSON library valuefloat always returns 0.00的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JSON 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准