title: How to parse json array in arduino IDE
body: <p>I am trying to parse a JSON array on a Pi server via wifi. I want to parse the following:</p>
  
  <blockquote>
    <p>[{"Device":"Curtain","Value":"1"},{"Device":"Fan","Value":"1"},{"Device":"Blinds","Value":"0"},{"Device":"Relay","Value":"0"}]</p>
  </blockquote>
  
  <p>Those are copied from the webpage:<a href="http://pi.access.com/states.php" rel="nofollow">http://pi.access.com/states.php</a></p>
  
  <p>the following are my Arduino code.</p>
  
  <pre><code>#include &lt;ArduinoJson.h&gt;
  
  void setup() {
    Serial.begin(9600);
    while (!Serial) {
      // wait serial port initialization
    }
  
    StaticJsonBuffer&lt;200&gt; jsonBuffer;    
  
    char   json[] =
    "[{\"Device\":\"Curtain\",\"Value\":\"1\"},{\"Device\":\"Fan\",\"Value\":\"1\"}]";
  
  
    JsonArray&amp; root = jsonBuffer.parseArray(json);
  
    // Test if parsing succeeds.
    if (!root.success()) {
      Serial.println("parseObject() failed");
      return;
    }
  
    // Fetch values.
  
    const char* device[] = root["Device"];
            int value[] = root["Value"];
  
    // Print values.
    Serial.println(device);
    Serial.println(value);
  
  }
  </code></pre>
  
  <p>Then I got a bunch of errors...</p>
  
  <pre><code>JsonParseExample.ino: In function 'void setup()':
  JsonParseExample:54: error: invalid conversion from 'const char*' to 'size_t {aka unsigned int}' [-fpermissive]
  In file included from /Users/Wei0928/Documents/Arduino/libraries/ArduinoJson/src/../include/ArduinoJson/JsonArray.hpp:181:0,
                   from /Users/Wei0928/Documents/Arduino/libraries/ArduinoJson/src/../include/ArduinoJson.h:9,
                   from /Users/Wei0928/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson.h:14,
                   from JsonParseExample.ino:8:
  /Users/Wei0928/Documents/Arduino/libraries/ArduinoJson/src/../include/ArduinoJson/JsonArray.ipp:16:27: error:   initializing argument 1 of 'ArduinoJson::JsonArraySubscript ArduinoJson::JsonArray::operator[](size_t)' [-fpermissive]
   inline JsonArraySubscript JsonArray::operator[](size_t index) {
                             ^
  JsonParseExample:54: error: initializer fails to determine size of 'device'
  JsonParseExample:54: error: array must be initialized with a brace-enclosed initializer
  JsonParseExample:58: error: call of overloaded 'println(const char* [1])' is ambiguous
  JsonParseExample.ino:58:24: note: candidates are:
  In file included from /Users/Wei0928/Documents/Arduino/libraries/ArduinoJson/src/../include/ArduinoJson/Internals/../Internals/../Arduino/Print.hpp:87:0,
                   from /Users/Wei0928/Documents/Arduino/libraries/ArduinoJson/src/../include/ArduinoJson/Internals/../Internals/DummyPrint.hpp:10,
                   from /Users/Wei0928/Documents/Arduino/libraries/ArduinoJson/src/../include/ArduinoJson/Internals/../Internals/JsonPrintable.hpp:11,
                   from /Users/Wei0928/Documents/Arduino/libraries/ArduinoJson/src/../include/ArduinoJson/Internals/../JsonVariant.hpp:13,
                   from /Users/Wei0928/Documents/Arduino/libraries/ArduinoJson/src/../include/ArduinoJson/Internals/../JsonBuffer.hpp:15,
                   from /Users/Wei0928/Documents/Arduino/libraries/ArduinoJson/src/../include/ArduinoJson/Internals/BlockJsonBuffer.hpp:10,
                   from /Users/Wei0928/Documents/Arduino/libraries/ArduinoJson/src/../include/ArduinoJson/DynamicJsonBuffer.hpp:10,
                   from /Users/Wei0928/Documents/Arduino/libraries/ArduinoJson/src/../include/ArduinoJson.h:8,
                   from /Users/Wei0928/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson.h:14,
                   from JsonParseExample.ino:8:
  /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:73:12: note: size_t Print::println(char) &lt;near match&gt;
       size_t println(char);
              ^
  /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:73:12: note:   no known conversion for argument 1 from 'const char* [1]' to 'char'
  /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:74:12: note: size_t Print::println(unsigned char, int) &lt;near match&gt;
       size_t println(unsigned char, int = DEC);
              ^
  /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:74:12: note:   no known conversion for argument 1 from 'const char* [1]' to 'unsigned char'
  /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:75:12: note: size_t Print::println(int, int) &lt;near match&gt;
       size_t println(int, int = DEC);
              ^
  /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:75:12: note:   no known conversion for argument 1 from 'const char* [1]' to 'int'
  /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:76:12: note: size_t Print::println(unsigned int, int) &lt;near match&gt;
       size_t println(unsigned int, int = DEC);
              ^
  /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:76:12: note:   no known conversion for argument 1 from 'const char* [1]' to 'unsigned int'
  /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:77:12: note: size_t Print::println(long int, int) &lt;near match&gt;
       size_t println(long, int = DEC);
              ^
  /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:77:12: note:   no known conversion for argument 1 from 'const char* [1]' to 'long int'
  /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:78:12: note: size_t Print::println(long unsigned int, int) &lt;near match&gt;
       size_t println(unsigned long, int = DEC);
              ^
  /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:78:12: note:   no known conversion for argument 1 from 'const char* [1]' to 'long unsigned int'
  JsonParseExample:59: error: 'value' was not declared in this scope
  invalid conversion from 'const char*' to 'size_t {aka unsigned int}' [-fpermissive]
  </code></pre>
  
  <p>Top of that I still haven't figured out how to read the array individually.
  Any advice is appreciated.</p>