Reputation: 1900
I have Json data like below
{
"!type": "alarm",
"$": {
"12279": {
"!type": "alarm",
"title": "Default",
"$": {
"5955": {
"!type": "alarm",
"name": "Wake",
"day": "SUN",
"startTime": "06:00"
},
"29323": {
"!type": "alarm",
"name": "Away",
"day": "SUN",
"startTime": "08:00"
},
"2238": {
"!type": "alarm",
"name": "Home",
"day": "SUN",
"startTime": "18:00"
}
}
}
}
}
My fbs looks like this
namespace space.alarm;
table Atom{
!type:string;
name:string;
startDay:string;
startTime:string; }
table AtomShell{
key:string (required, key);
value: Atom; }
table Alarm{
!type:string;
title:string;
$:[AtomShell]; }
table AlarmShell{
key:string (required, key);
value:Alarm; }
table Weeklyalarm{
!type:string;
$:[AlarmShell]; } root_type Weeklyalarm;
Im trying to implement google flat buffers but I'm getting errors like
Now my question,
Thanks in advance.
Upvotes: 0
Views: 308
Reputation: 6074
You can't have characters like !
and $
in field names. Just use type
instead of !type
, etc.
Not sure what you mean by dynamic ids. All field names (keys) have to be declared in the schema, so they can't be dynamic. You can still achieve similar results though, if you make your JSON look something like this:
{
"type": "alarm",
"data": [
{
id: "12279",
"type": "alarm",
"title": "Default",
"data": [
{
"id": "5955",
"type": "alarm",
"name": "Wake",
"day": "SUN",
"startTime": "06:00"
},
{
"id": "29323",
"type": "alarm",
"name": "Away",
"day": "SUN",
"startTime": "08:00"
},
{
"id": "2238",
"type": "alarm",
"name": "Home",
"day": "SUN",
"startTime": "18:00"
}
]
}
]
}
And then make the corresponding schema.
Note that I made the "dynamic" list into a vector, and moved the id into the object itself.
Other tip: string values that are not dynamic (like "alarm"
) will take up way less space if you make them into an enum instead.
Upvotes: 0