SHARE
TWEET

Don't understand how to use 2D char array arduino

a guest Jul 28th, 2013 403 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //I am getting this error:
  2. //Parsing:60: error: scalar object 'jsonFilter' requires one element in initializer
  3.  
  4. /*
  5.  Sample sketch to demonstrate Multi Level JSON parsing in Arduino
  6.  
  7.  This sketch parses the complexly nested JSON
  8.  
  9.  Libraries needed:
  10.  
  11.  - aJson library for JSON parsing - https://github.com/interactive-matter/aJson
  12.  
  13.  Circuit:
  14.  
  15.     You don't need any circuit, but need the Arduino board
  16.  
  17.  Author:
  18.  
  19.     Sudar - <http://sudarmuthu.com> <http://hardwarefun.com>
  20.     Refer to http://hardwarefun.com/tutorials/parsing-json-in-arduino
  21.  
  22.  License:
  23.  
  24.     BeerWare ;)
  25.  
  26.  */
  27. #include <aJSON.h>
  28.  
  29. // function definitions
  30. char* parseJson(char *jsonString) ;
  31. //char** jsonFilter;me
  32.  
  33. // Json string to parse
  34. char jsonString[] = "{\"query\":{\"count\":1,\"created\":\"2012-08-04T14:46:03Z\",\"lang\":\"en-US\",\"results\":{\"item\":{\"title\":\"Handling FTP usernames with @ in them\"}}}}";
  35.  
  36. void setup() {
  37.     Serial.begin(9600);
  38.     Serial.println(jsonString);
  39.     Serial.println("Starting to parse");
  40.  
  41.     char* value = parseJson(jsonString);
  42.  
  43.     if (value) {
  44.         Serial.print(F("Successfully Parsed: "));
  45.         Serial.println(value);
  46.     } else {
  47.         Serial.print(F("There was some problem in parsing the JSON"));
  48.     }
  49. }
  50.  
  51. /**
  52.  * Parse the JSON String. Uses aJson library
  53.  *
  54.  * Refer to http://hardwarefun.com/tutorials/parsing-json-in-arduino
  55.  */
  56.  
  57. char* parseJson(char *jsonString)
  58. {
  59.     char* value;
  60.  
  61.  //   aJsonObject* root = aJson.parse(jsonString);
  62.  
  63.  char** jsonFilter = {"name","format","height","width",NULL};
  64.  aJsonObject* root = aJson.parse(jsonString,jsonFilter);
  65.  
  66.     if (root != NULL) {
  67.         //Serial.println("Parsed successfully 1 " );
  68.         aJsonObject* query = aJson.getObjectItem(root, "query");
  69.  
  70.         if (query != NULL) {
  71.             //Serial.println("Parsed successfully 2 " );
  72.             aJsonObject* results = aJson.getObjectItem(query, "results");
  73.  
  74.             if (results != NULL) {
  75.                 //Serial.println("Parsed successfully 3 " );
  76.                 aJsonObject* item = aJson.getObjectItem(results, "item");
  77.  
  78.                 if (item != NULL) {
  79.                     //Serial.println("Parsed successfully 4 " );
  80.                     aJsonObject* title = aJson.getObjectItem(item, "title");
  81.                    
  82.                     if (title != NULL) {
  83.                         //Serial.println("Parsed successfully 5 " );
  84.                         value = title->valuestring;
  85.                     }
  86.                 }
  87.             }
  88.         }
  89.     }
  90.  
  91.  
  92.     if (value) {
  93.         return value;
  94.     } else {
  95.         return NULL;
  96.     }
  97. }
  98.  
  99. void loop() {
  100.    // Nothing to do
  101.    ;
  102. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top