|
|
Comments and Discussions
|
|
 |

|
Point and Size (and other GDI types etc.) require the CustomType to be enabled as they are not supported by fastJSON ( you have to write de/serializers for them yourself).
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
Hi Mehdi,
I'm very impressed with your implementation here. Particularly your performance results - the results against BinaryFormatter are very telling - and the fact that you beat Stack. I prototyped my own binary serializer a few years ago (never went into production), that was around 40x faster than the binary serializer, so I can appreciate a text-based format beating the binary formatter.
I actually needed fastJSON for it's ability to deserialize the more complex OO types. I can't believe that Stack resisted your requests. Although it would be good to call your solution a JSON and JSONOO serializer, for clarity.
Also, I have thoughts of re-visiting my binary formatter, now called eXtensible Binary eXchange (XBX). I particularly want to use it with Javascript over WebSockets. I would build it open source, and it would be tunable and configurable, with default setup for fulfilling most applications, but able to be tuned to minimize payload and maximize performance.
Please contact me if you would like more details and would like to help. I can share my draft Google Doc and we could work on the specification first, and possibly co-author another codeproject article.
|
|
|
|

|
Hello everyone, I can not do with json decode, please help?
string jsonText = "[[{\"language\":\"es\",\"isReliable\":false,\"confidence\":0.4517133956386293},{\"language\":\"pt\",\"isReliable\":false,\"confidence\":0.08356545961002786}],[{\"language\":\"en\",\"isReliable\":false,\"confidence\":0.17017828200972449},{\"language\":\"vi\",\"isReliable\":false,\"confidence\":0.13673655423883319}]]}}";
var newobj = fastJSON.JSON.Instance.ToObject<List<SubFolder>>(jsonText);
private class SubFolder
{
public string language { get; set; }
public string isReliable { get; set; }
public string confidence { get; set; }
}
> the array would be this:
{"data":{"detections":[[{"language":"es","isReliable":false,"confidence" .4517133956386293},{"language":"pt","isReliable":false,"confidence" .08356545961002786}],[{"language":"en","isReliable":false,"confidence" .17017828200972449},{"language":"vi","isReliable":false,"confidence" .13673655423883319}]]}}
|
|
|
|

|
First a List<SubFolder> becomes [{"language":null,"isReliable":null,"confidence":null},{"language":null,"isReliable":null,"confidence":null}]
Note the single square bracket, so your json string is not correct.
Second the types must be public and not private for fastJSON to work.
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
Im happy with this lib first of all,
but I recently found a bug
you can cast an int[][] from the json string "[[0,0,2]]"
Greetings
|
|
|
|

|
Do you have some sample code for this?
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
this will throw an exception that it can't cast an int[][] from an int[]
fastJSON.JSON.Instance.ToObject<int[][]>>("[[0,0,2]]");
|
|
|
|

|
Hello, Just wanted to ask, if there are any plans of making fastJSON available to WinRT platform? Regards, Dovydas
|
|
|
|

|
Thanks Dovydas!
Currently I don't have the resources for WinRT testing, judging by the Silverlight debacle WinRT will probably not work, I don't know.
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
Change fastJSON version from 1.9.6 to current version 2.0.13 and now I cannot longer deserialize classes with enum properties. Always get exception "InvalidCastException: Cannot convert type System.Int64 to type System.String".
Compiling fastJSON for .NET 2.0
Any ideas?
Best regards,
Markus
|
|
|
|

|
Thanks Mark!
Can you give me a sample code that you have problems with?
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
If jp.UseOptimizedDatasetSchema is set with false and the json text with dataset is handled by the method "Beautify", the dataset's xml schema in the json text will be not well-formed. I guess that the method of "Formatter.PrettyPrint" is not implemented correctly.
|
|
|
|

|
Modification 1: // StringBuilder replaced with string public static bool IsEscaped(string sb, int index) { bool escaped = false; while (index > 0 && sb[--index] == '\\') escaped = !escaped; return escaped; } Modification 2: case '"': case '\'': output.Append(ch); if (!IsEscaped(input, i)) // not using output // The length of output is unexpected.
|
|
|
|

|
Thanks! I will look into it and post soon.
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
I had this bug too and the modifications helped.
|
|
|
|

|
A bug !!! All objects must be declared with "public", otherwise, the exception - failed to fast create instance - will be threw during deserialization from JSON text.
|
|
|
|

|
In the words of Huey Lewis : "that's the way it is".
Generally serializers work with public classes, properties and fields, and fastJSON is no exception.
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
I am having problems using fastJSON in my Silverlight 4 application.
When I call: fastJSON.JSON.Instance.ToJSON(myObject);
I get an exception here:
DynamicMethod getter = new DynamicMethod("_", typeof(object), new Type[] { typeof(object) }, type);
Exception:
Attempt by security transparent method 'fastJSON.Reflection.CreateGetMethod(System.Type, System.Reflection.PropertyInfo)' to access security critical method 'System.Reflection.Emit.DynamicMethod..ctor(System.String, System.Type, System.Type[], System.Type)' failed.
Do you have any idea how I could get this fixed?
I took the fastJSON-SL project and builded. Then added the .dll to my SL app.
Best Regards
Frederik
|
|
|
|

|
Right click on your application and make sure the Silverlight version is 4 and not 5.
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
Can you compare performance with
|
|
|
|

|
Last time I checked they were not polymorphic.
(SerivceStack is compared in the article).
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
I was reviewing some of the code and noticed that you target .NET 4.0 but are using monitor locks for dictionary access. This isn't altogether terrible, but figured you might like to know MS has added concurrency oriented collections and ConcurrentDictionary<K,V> might be to your liking. It also better encapsulates common atomic operations like GetOrAdd and AddOrUpdate. Besides that, the main reason I'm avoiding this for now is the lack of Stream support. I have network and file stream data that would be inconvenient to load into memory entirely (some rather large data at times). Since you're using a forward moving tokenizer I don't think this would be entirely too difficult using a TextReader. Thanks for the article and code
|
|
|
|

|
Thanks!
In my tests (a while back) the concurrent dictionary was slower than the one in fastJSON.
TextReader and streams were slow also.
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
How does fastJson handle circular references? Json.Net has a setting that limits circular references whereas the .NET Json serializer throws an error but I did not see any mention in your article about handling circular references with fastJson.
If you could comment, I would appreciate it.
|
|
|
|

|
fastJSON will go 10 levels deep into any object structure, (this is a configuration parameter).
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
Thank you for the information. Where can this be configured so I can only have it go 1 or 2 deep?
|
|
|
|

|
internal sealed class JSONSerializer
{
private StringBuilder _output = new StringBuilder();
private StringBuilder _before = new StringBuilder();
readonly int _MAX_DEPTH = 10;
...
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|
|

|
Thanks!
I will fix this.
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
Fixed in v2.0.13
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
Line 328 in JsonSerializer.cs
maybe int c = g.Count; is int c = g.Count + 1; ?
test data is (type Test is struct):
Test data = new Test(1,"Test","Test");
serialized string is (but incorrect):
{"Id":1,"Name":"Test""Picture":"Test"}
after modifying source code:
{"Id":1,"Name":"Test","Picture":"Test"}
|
|
|
|

|
I have the same bug.
@QK5762: Your fix works for me as well.
|
|
|
|

|
Ah these commas are killing me!
This patch fails in CommaTests().
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
Fixed in v2.0.13
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
Ah these commas are killing me!
This patch fails in CommaTests().
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
Fixed in v2.0.13
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
Consecutive NULL parameters in class, with SerializeNullValues = false produces multiple commas.
eg.
var objTest = new
{
A = "foo",
B = (object)null,
C = (object)null,
D = "bar"
};
jsonInstance = JSON.Instance;
jsonInstance.Parameters = new JSONParameters
{
EnableAnonymousTypes = false,
IgnoreCaseOnDeserialize = false,
SerializeNullValues = false,
ShowReadOnlyProperties = true,
UseExtensions = false,
UseFastGuid = true,
UseOptimizedDatasetSchema = true,
UseUTCDateTime = false,
UsingGlobalTypes = false,
UseEscapedUnicode = false
};
var json = JsonFormatter.JSON.ToJSON(objTest);
json = {"A":"foo",,"D":"bar"}
|
|
|
|

|
Thanks Mabakay!
I will look into it and post a fix soon.
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
look at the code:
Version oVer = new Version("2012.12.12");
string sNewSer41 = fastJSON.JSON.Instance.ToJSON(oVer);
Version oTest41 = fastJSON.JSON.Instance.ToObject<Version>(sNewSer41);
sNewSer41 parameter is right.
but when deserialize it to Version instance,i find it can't success to deserialize.
Last One Code
|
|
|
|

|
I haven't tested that, if you need it you can write your own custom serializer/deserializer for that type, see the article.
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
look at this:
NameValueCollection oCollect = new NameValueCollection(2);
oCollect.Add("key1","value1");
oCollect.Add("key2","value2");
When call the method:
fastJSON.JSON.Instance.ToJSON(oCollect)
it can't get the right result.then i debug the source,finally i find the code in "JsonSerializer.cs" here:
if (obj is Array || obj is IList || obj is ICollection)
WriteArray((IEnumerable)obj);
in fact,NameValueCollection is a key/value collection,although it implement the ICollection interface.
so when NameValueCollection casted IEnumerable interface,it could only serialize NameValueCollection's key.
I think we can add one piece code before that code:
else if (obj is NameValueCollection)
WriteNameValueCollection((NameValueCollection)obj);
the WriteNameValueCollection() method can implement as IDictionary. it that right?
Last One Code
|
|
|
|

|
That could work, I will test and add it in the next release.
Thanks!
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
Hi Mehdi
I noticed that included in the solution there is a Mono for Android project. I also need to run the code on iOS (MonoTouch).
Since the use of reflection on iPhone is limited, I wonder what needs to be done to make fastJSON work without the "Emit" in Refelection.cs (and probably would be called "a little bit less fastJSON" )
I am not too familiar with Reflection Emit myself, but basically creating a slower (non-emit) version of FastCreateInstance, CreateSetField, CreateSetMethod, CreateGetField, CreateGetMethod would do the job ?
Thanks
Gerd
Edit : fastJASON => fastJSON
modified 18-Dec-12 18:07pm.
|
|
|
|

|
It would be possible, although using normal reflection is really slow.
I don't have the resources to test this, so it won't be going on my todo list anytime in the future.
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
I just took a very quick initial attempt at replacing the Emit methods in a trivial way. I don't know what I'm doing yet, but 30 out of 34 unit tests pass, (compared to 33 out of 34), so that might be a sign of a good start:
[Update: I got serialization working on my iPhone in Unity3D! Still some exceptions related to casting parameters though.]
http://fastjson.codeplex.com/SourceControl/network/forks/jaredthirsk/fastjsonaot[^]
(I am a MonoTouch user, and a Unity3D user. Unity3D uses an older version of mono that only supports .NET 3.5, so for my fork I set things back to 3.5. Also note you need to pay money to get System.Data.dll support, since it pulls in System.Net.dll, which is a restricted feature for Unity iPhone Basic users like me (got it while it was free).)
(Gotta love git for making forking so easy! And liberal licenses so we can actually use this on iOS devices )
modified 23-Dec-12 10:03am.
|
|
|
|

|
Nice!
Performance?
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
Here are some initial numbers: I need to redo the iOS devices to make sure that only the benchmark is running, and no parallel loading is running at the same time.
Another idea I have is to generate the code on a non-AOT machine, save the DLL, and use that on the iOS device.
===================
Macbook Air 1.8Ghz Core i7 - unmodified version
1) Exotic = on
.net version = 4.0.30319.1
press key : (E)xotic
exotic: True
-dataset
Loaded assembly: /Users/jared/Dev/fastjson/consoletest/bin/Release/fastJSON.dll
fastjson serialize 470.98 303.752 309.807 369.708 322.61
fastjson deserializeLoaded assembly: Anonymously Hosted DynamicMethods Assembly [External]
418.443 354.359 427.11 396.857 357.585
+dataset
fastjson serialize 2209.215 2412.338 2232.666 2762.409 2697.409
fastjson deserialize 3508.546 3411.204 3817.756 3442.679 3588.831
2) Exotic = off
.net version = 4.0.30319.1
press key : (E)xotic
exotic: False
-dataset
Loaded assembly: /Users/jared/Dev/fastjson/consoletest/bin/Release/fastJSON.dll
fastjson serialize 261.276 135.076 139.305 136.973 144.693
fastjson deserializeLoaded assembly: Anonymously Hosted DynamicMethods Assembly [External]
184.429 137.761 134.304 134.464 140.832
+dataset
fastjson serialize 134.165 156.669 135.001 146.152 141.247
fastjson deserialize 141.077 145.901 142.572 148.793 142.273
===================
Macbook Air 1.8Ghz Core i7 - AOT-ready version
.net version = 2.0.50727.1433
1) exotic: True, -dataset
fastjson serialize 487.221 378.449 354.955 336.408 334.877
fastjson deserialize [Throws exception: failed to convert parameters]
2) exotic: False,
-dataset
fastjson serialize 209.038 145.409 145.875 140.096 139.527
fastjson deserialize 239.797 212.647 203.514 203.731 203.22
+dataset
fastjson serialize 151.081 139.864 138.69 139.428 142.64
fastjson deserialize 204.956 201.531 203.411 209.698 216.497
===================
iPhone 3GS in Unity3D 3.5.6f4
.net version = 2.0.50727.1433
mono verison = 2.6.5 (tarball)
1) exotic: True, -dataset (dataset not available on this build configuration, requires Unity iOS Advanced license )
fastjson serialize 10422.149 13057.857 10384.186 10362.458 10410.323
fastjson deserialize System.ArgumentException: failed to convert parameters
2) exotic: False
-dataset (dataset not available on this build configuration, requires Unity iOS Advanced license )
fastjson serialize 4790.826 4783.832 4769.139 4922.623 4789.749
fastjson deserialize 4521.374 4526.947 4585.467 4560.347 4510.281
===================
iPad 3rd Generation in Unity3D 3.5.6f4 (Mono)
.net version = 2.0.50727.1433
mono verison = 2.6.5 (tarball)
1) exotic: True, -dataset (dataset not available on this build configuration, requires Unity iOS Advanced license )
fastjson serialize 2810.423 2806.981 2837.854 2809.805 2816.258
fastjson deserialize System.ArgumentException: failed to convert parameters
2) exotic: False, -dataset (dataset not available on this build configuration, requires Unity iOS Advanced license )
fastjson serialize 1290.438 1296.072 1288.941 1293.648 1306.058
fastjson deserialize 1228.635 1224.022 1236.638 1227.458 1230.802
modified 29-Dec-12 22:00pm.
|
|
|
|

|
Hi Mehdi,
I noticed that Code Project lists this article and associated code as being under the CPOL (both on the right navbar and at the end of the article), while Codeplex (and as a result nuget) has fastJSON listed as GPLv2.
This may not be something that you can change here (I'm not too familiar with how it works) but am I right in thinking that it's intended to be under the GPL (ie allowing no commercial use in larger non-opensource works etc) instead of CPOL?
Many thanks!
|
|
|
|

|
The license agreement has always been a pain and I have changed it (on codeplex) a number of times and each time someone is not happy, so I have given up!
You can use fastJSON as you see fit.
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|

|
Awesome, thanks!
It really looks like a great piece of software, and I just wanted to make sure that I wouldn't unintentionally be running afoul of the licensing / misusing your hard work before diving in too much.
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
|
Smallest, fastest polymorphic JSON serializer (with Silverlight4 and MonoDroid support)
| Type | Article |
| Licence | CPOL |
| First Posted | 19 Feb 2011 |
| Views | 1,601,010 |
| Downloads | 26,664 |
| Bookmarked | 467 times |
|
|