Getting underlying struct for parseJSON

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Feb 28 13:21:30 PST 2017


On Tuesday, 28 February 2017 at 20:27:25 UTC, Alexey H wrote:
> So, my real question is: can i actually, by any change, get the 
> description of an underlying struct that the call to parseJSON 
> generates?

It doesn't actually generate one, it just returns a tagged union 
(a kind of dynamic type).

But, my json inspector program (never finished btw) has something 
that can kinda generate structs from json: 
https://github.com/adamdruppe/inspector

I ran your data.json through my program, and it spat this out 
(well, not directly, I did a few minor tweaks by hand since it 
doesn't output 100% valid D, but it is a good start):

struct Json_t {
	struct sports_t {
		long regionId;
		string name;
		long id;
		string sortOrder;
		long parentId;
		string kind;
	}
	sports_t[] sports;

	long siteVersion;

	struct eventBlocks_t {
		long[] factors;
		long eventId;
		string state;
	}
	eventBlocks_t[] eventBlocks;

	struct customFactors_t {
		long lo;
		long e;
		bool isLive;
		double v;
		string pt;
		long f;
		long p;
		long hi;
	}
	customFactors_t[] customFactors;

	struct announcements_t {
		long segmentId;
		string place;
		bool liveHalf;
		long regionId;
		string name;
		long[] tv;
		string segmentName;
		string segmentSortOrder;
		long id;
		long num;
		string namePrefix;
		string team1;
		long startTime;
		long sportId;
		string team2;
	}
	announcements_t[] announcements;

	struct events_t {
		long level;
		string sortOrder;
		string place;
		string name;
		long rootKind;
		long parentId;
		long id;
		long num;
		string namePrefix;
		string team1;
		long kind;
		struct state_t {
			bool inHotList;
			bool willBeLive;
			bool liveHalf;
		}
		state_t state;
		long startTime;
		long sportId;
		long priority;
		string team2;
	}
	events_t[] events;
	long packetVersion;
	struct eventMiscs_t {
		long liveDelay;
		long timerUpdateTimestamp;
		long[] tv;
		string comment;
		long score2;
		long servingTeam;
		long id;
		long timerSeconds;
		long timerDirection;
		long score1;
	}
	eventMiscs_t[] eventMiscs;
	long fromVersion;
	long factorsVersion;
}


And I *think* my jsvar.d has magic methods to load up one of 
those.... but since my jsvar.d just uses std.json and then builds 
up junk on top of it, it will necessarily be even slower than 
what you already have :S so meh.



More information about the Digitalmars-d-learn mailing list