运行示例ArduinoJson时出错

时间:2014-08-01 04:26:52

标签: c json arduino

我无法从https://github.com/bblanchon/ArduinoJson

运行示例

我已经安装了库并运行了一个简单的例子。

/*
* Arduino JSON library - Parser Example
* Benoit Blanchon 2014 - MIT License
*/

#include <JsonParser.h>

using namespace ArduinoJson::Parser;

void setup()
{
    Serial.begin(9600);

    char json [] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
    JsonParser<16> parser;
    JsonObject root = parser.parse(json);

    if (!root.success())
    {
        Serial.println("JsonParser.parse() failed");
        return;
    }

    char*  sensor    = root["sensor"];
    long   time      = root["time"];
    double latitude  = root["data"][0];
    double longitude = root["data"][1];

    Serial.println(sensor);
    Serial.println(time);
    Serial.println(latitude, 6);
    Serial.println(longitude, 6);
}

void loop()
{
}

但是我收到了这个错误:

JsonParserExample:8: error: 'ArduinoJson' has not been declared
JsonParserExample:8: error: 'Parser' is not a namespace-name
JsonParserExample:8: error: expected namespace-name before ';' token
JsonParserExample.ino: In function 'void setup()':
JsonParserExample:18: error: 'JsonObject' was not declared in this scope
JsonParserExample:18: error: expected `;' before 'root'
JsonParserExample:20: error: 'root' was not declared in this scope
JsonParserExample:26: error: 'root' was not declared in this scope

命名空间似乎有问题,但我无法找到它..

1 个答案:

答案 0 :(得分:1)

我尝试下载它,它的工作原理。 我使用的是Arduino IDE 1.0.5 r2。

你是否正确&#34;安装&#34;图书馆?我的意思是

  1. 从github下载档案(例如点击&#34;下载ZIP&#34;,在右侧)
  2. 将内容提取到&#34;库&#34;草图文件夹中的文件夹
  3. 重命名&#34; ArduinoJson&#34;
  4. 中的文件夹
  5. 启动Arduino IDE
  6. 在第三点你应该有文件

    <your sketch dir>\libraries\ArduinoJson\ArduinoJson.sln
    <your sketch dir>\libraries\ArduinoJson\CHANGELOG.md
    <your sketch dir>\libraries\ArduinoJson\JsonParser\JsonParser.vcxproj
    and so on
    

    如果你在Arduino IDE中以正确的方式完成了所有工作,你应该在File-&gt; Examples下看到ArduinoJson文件夹,里面有两个例子。

相关问题