Usage of custom class with JSONValue

Andre via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 24 01:15:12 PDT 2016


Hi,

I have a class which has already an alias this to a string array,
so I can use it in a foreach loop.

class MyClass
{
	string[] _data;
	alias _data this;
	// ...
}

void main()
{
	import std.json;
	auto jsValue = JSONValue(new MyClass());
}

For some generic code I need an implicit conversion of MyClass so 
I can
use it for a JSONValue. For the coding above I receive a compiler 
error:
static assert  "unable to convert type "MyClass" to json"

Is there anything I can do?

Kind regards
André



More information about the Digitalmars-d-learn mailing list