Arduino JSON and struct datatypes

Hi all,
I’m playing arround with the ArduinoJson.h and getting into troubles with struct datatypes. I wrote a little program:

#include <ArduinoJson.h>

struct data 
{
	int counter;
	int number;
	char text;
};

typedef data dataset;

#include <ArduinoJson.h>

void JSON()
{
	
	StaticJsonBuffer<200> jsonBuffer;
	JsonObject& root = jsonBuffer.createObject();
	root["number"] = dataset.number;
}

void setup()
{
	dataset.number = 10;


}

void loop()
{

	JSON()

}

I would like to pass a variable of the type data named dataset to the JSON function, but it shows me this error message:

JSON.ino: In function void JSON()
 
JSON.ino: 34:26: error: expected primary-expression before '.' token
   root["number"] = dataset.number
Error compiling project sources
Build failed for project 'JSON'
 
JSON.ino: In function void setup()
 
JSON.ino: 40:9: error: expected unqualified-id before '.' token
   dataset.number = 10
 
JSON.ino: In function void loop()
 
JSON.ino: 51:1: error: expected ';' before '}' token

Can anybody give me a hint to fix it?

Thank you very much!

BR
Chris

Can anybody give me a hint to fix it?

Fire up a text editor, and fix the problem(s).

Without seeing your code, you can't expect us to help you.

ard24:

struct data 

{
int counter;
int number;
char text;
};
typedef data dataset;

dataset.number = 10;

You have created a type called dataset, but not an instance of that type - a concrete variable or object.
Just remove the typedef keyword, and don’t forget the semicolon after JSON().

You have created a type called dataset,

But not a valid type.

The type that OP seems to trying to alias is struct data, not data.

Hi all,
thank you very much for your help. I understand now. My mistake was, I created just a new name for the datatype “data” but not an instance due to using typedef.

But now I would like to create an array of the type data called dataset[10] for example.

#include <ArduinoJson.h>

struct data
{
	int counter;
	int number;
	char text;
};

data dataset[10];

#include <ArduinoJson.h>

void JSON()
{
	
	StaticJsonBuffer<200> jsonBuffer;
	JsonObject& root = jsonBuffer.createObject();
	root["number"] = dataset.number[0];
}

void setup()
{
	dataset.number = 10;
}

void loop()
{
	JSON();
}

But this now generates a error message non-class type:

Compiling 'test' for 'ATmega1284'
 
test.ino: In function void JSON()
 
test.ino: 19:27: error: request for member 'number' in 'dataset', which is of non-class type 'data [10]
   root["number"] = dataset.number[0]
Error compiling project sources
Build failed for project 'test'
 
test.ino: In function void setup()
 
test.ino: 24:10: error: request for member 'number' in 'dataset', which is of non-class type 'data [10]
   dataset.number = 10

Is there a trick to solve this?

Thank you very much!
Chris

Your type is NOT data. It is struct data.

struct data dataset[10];

Hi PaulS,
thank you very much for your fast reply. It's a bit complicated for me, but I guess i've got it so far.

There is a difference between a datatype and a struct. I mixed it. But also by writing:

struct data dataset[10];

the compiler gives me the same error message like above?

the compiler gives me the same error message like above?

Is that a question or a statement?

The array of objects does not have a member named number. ONE element of the array would.