var table = new MyTableObject();
MyTableObject.someField = "Hello world!";
trace( Json.stringify( table ) );
Hi Juraj,
I'm not sure how I could apply a custom serialization.
I looked already at the docs but I'm not sure how I could apply that to spod objecs. Would I have to make a costum serializator for each spod object, or just one for all spod objects.
At the moment I have a temporary noobish solution that works but it's not very efficient.
The code fails when accessing one of the following fields:
_manager
_lock
__cache__
So I skip them inside a loop since their names are prefixed by an underscore:
private function toJson( tableData : List<Dynamic> ) : String{ var jsonTable : Array<Dynamic> = []; for( rowData in tableData ) { var jsonRow : Dynamic = {}; for( fieldName in Reflect.fields( rowData ) ) { if( fieldName.substr( 0, 1 ) != "_" ) { Reflect.setField( jsonRow, fieldName, Reflect.field( rowData, fieldName ) ); } } jsonTable.push( jsonRow ); } return Json.stringify( jsonTable );}
--To post to this group haxe...@googlegroups.com---You received this message because you are subscribed to the Google Groups "Haxe" group.To unsubscribe from this group and stop receiving emails from it, send an email to haxelang+u...@googlegroups.com.For more options, visit https://groups.google.com/groups/opt_out.