2014-07-26 3 views
0

나는 ArduinoJson 라이브러리를 사용하고 있습니다. 소스 코드에서 단일 JSON 객체를 구문 분석하기위한 great example이 있습니다. 내가 JSON 객체의 배열을 반복하려고 시도하고있다 : Arduino에서 JSON 구문 분석

#include <JsonParser.h> 

using namespace ArduinoJson::Parser; 

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

    char json[] = "[{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}, \ 
    {\"sensor\":\"gps\",\"time\":1351824140,\"data\":[50.756080,21.302038]}]"; 

    JsonParser<32> parser; 
    JsonArray root = parser.parse(json); 

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

    for (JsonArrayIterator item = root.begin(); item != root.end(); ++item) { 
    // unsure of what to do here. 

    Serial.println((*item)["data"]); 
    // results in: 
    // ParseJsonArray:21: error: call of overloaded 
    // 'println(ArduinoJson::Parser::JsonValue)' is ambiguous 

    JsonObject something = JsonObject(*item); 
    Serial.println(something["sensor"]); 
    // results in : 
    // ParseJsonArray:26: error: call of overloaded 
    // 'println(ArduinoJson::Parser::JsonValue)' is ambiguous 
    } 
} 

void loop() {} 

item

유형 JsonValue이다. 나는 그것을 JsonObject로 취급하고 그것을 밖으로 끌어 내고 싶다.

답변

0
char* sensor = (*item)["sensor"]; 
Serial.println(sensor);