I’m just about finished with a drop-in replacement for JSONItem. It’s all Xojo code and emulates all features and functionality of the native class, except:
It’s around as fast, if not faster, to create and load.
It handles Unicode characters correctly for both values and, in objects, names.
It throws an exception if you try to add a value it can’t handle rather than waiting until you call ToString.
It is something like 40 times faster when generating large JSON strings. (That is not a typo.)
The last point is why I undertook the project at all. In my test case of 10,000 objects, it takes the native class 4.7 seconds to render a string. It takes my class around 106 milliseconds.
To use it, you’d find and replace all occurrences of JSONItem with JSONItem_MTC, then drag the class to your project.
If there is interest, I will post this as an open-source project on my web site when I get back from vacation. Is there interest?
Another thing: Please talk to Xojo engineers about it. Because if it’s so fast, why not give it to Xojo Inc. and let it become the new implementation of JSONItem class?
That would speed up all the web stuff instantly.
Another thing: Please talk to Xojo engineers about it. Because if it’s so fast, why not give it to Xojo Inc. and let it become the new implementation of JSONItem class?
That would speed up all the web stuff instantly.[/quote]
+1
And Kem’s name should be mentioned in the docs for this contribution.
An additional version on github or Kem’s website would be great also. So we can individually adapte his code if necessary.
I like the idea of perhaps Xojo being able to build it in if compatible, as long as it has a BSD, MIT or other permissive license there’s a chance they’ll look at it.
[quote=120558:@Christian Schmitz]Another thing: Please talk to Xojo engineers about it. Because if it’s so fast, why not give it to Xojo Inc. and let it become the new implementation of JSONItem class?
That would speed up all the web stuff instantly.[/quote]
I plan to release it as open source and free to use by anyone for any purpose, including by Xojo. (That would be neat though. )
This is cool. I did not even know there was a class built-in to Xojo for this. I have worked with JSON text generating and I did not use a class. Good to know about your project Kem, thanks.
Is there an existing Interface like “StringProvider” or the like? For example, suppose I have an object that can be converted to a string, and I want the world to know. Is there some interface for that purpose?
If not, would it be useful to add that and have my class recognize it? It would mean adding two items to your project instead of the one.
What’s the best approach to find the existence of a method in a object and invoke it in Xojo?
The ToString() probably could be part of some kind of Serializable Interface.