|
|
Comments and Discussions
|
|
 |

|
Hi, when I use notation "NameSpace1.MyClass" && "NameSpace2.MyClass" fastJSON think that they are equals! Please, fix this bug. JSON.cs @@ -440,7 +440,7 @@ if (type == null) throw new Exception("Cannot determine type"); - string typename = type.Name; + string typename = type.FullName; object o = FastCreateInstance(type); SafeDictionary<string, myPropInfo> props = Getproperties(type, typename); foreach (string name in d.Keys)
|
|
|
|

|
Hi, I've added the following to this little beast
inside JSON.cs
private DataSet CreateTypedDataset(Dictionary<string, object> reader, Type t)
{
var ds = Activator.CreateInstance(t);
((DataSet)ds).Locale = CultureInfo.InvariantCulture;
((DataSet)ds).EnforceConstraints = false;
((DataSet)ds).BeginInit();
foreach (var pair in reader)
{
if (pair.Key == "$type" || pair.Key == "$schema") continue;
var rows = (ArrayList)pair.Value;
if (rows == null) continue;
var dt = ((DataSet)ds).Tables[pair.Key];
ReadDataTable(rows, dt);
}
((DataSet)ds).EndInit();
return (DataSet)ds;
}
and then inside private object ParseDictionary(Dictionary<string, object> d, Type type)
if (found == false && type.BaseType == typeof(DataSet))
{
return CreateTypedDataset(d, type);
}
Since strongly typed dataset already have the schema embedded we can serialize using
fastJSON.JSON.Instance.ToJSON(data, false, true, true, true)
deserialization is done by using:
fastJSON.JSON.Instance.ToObject<T>(json)
|
|
|
|

|
Hi,
really nice serializer.
I use it to serialize/deserialize strongly typed datasets.
there is one small problem. for multilanguage apps that set the currentculture of the current thread you must set
ds.Locale = CultureInfo.InvariantCulture; after
DataSet ds = new DataSet();
in private DataSet CreateDataset(Dictionary<string, object> reader) inside JSON.cs, otherwhise number/datetime conversion might fail.
I have one question. How to deserialize correctly a strongly typed dataset?
First I've tried the obvious:
fastJSON.JSON.Instance.ToObject<CustomerData>(json);
but it doesn't recognize it as a dataset.
It worked fine with (DataSet)fastJSON.JSON.Instance.ToObject(json, typeof(object));
but it's a little weird. Am I doing something wrong? Thanks.
modified on Thursday, July 7, 2011 10:29 AM
|
|
|
|

|
I am having problems converting this to an object structure due to multi array i think.
https://mtgox.com/code/data/getDepth.php[^][^]
the issue i think is the array inside the array. I actually wanted to read that inner array as a class instead of an array with a custom seriliser/deseriliser for the class but it did not get called as it is an array not a class.
Is there any way to read this data into objects without having to parse the data manually? Sadly i can change the json as i have no control of the source.
|
|
|
|

|
How does fastJSON handles object with circular reference? For example an Order has a list of OrderDetails, in which each has a reference back to its parent Order.
It seems fastJSON simply throw an exception when _MAX_DEPTH is reached. Any other better solution for this?
Thank you!
David
|
|
|
|

|
how generate jqGrid colmoder formatter function property like:
[{ name:"col1", formatter: function(v) {
return v;
}
} ]
function definition
@"function(v) {
return v;
}"
is multi-line user-defined skript retrieved form database at runtime.
.NET jsonserializer Serialize() method renders formatter in quotes and encodes characters like return, line feed, ", < and > producing invalid javasript code:
[{ "name":"col1", "formatter": "function(v) \r\n { return v; \r\n }" } ]
How to render formatter as normal javascript function definition ? Can fastjson or other serializer handle this ?
Andrus
|
|
|
|

|
I'm very new to Json but, as I understand things, it's a fairly compact text-based object notation. So if that's the case shouldn't this simple example work?
string before = "Hello World!"
string json = fastJSON.JSON.Instance.ToJSON(before);
string after = (string)fastJSON.JSON.Instance.ToObject(json);
Console.WriteLine ("Before: " + before + " After: " + after);
I must be missing something very simple...but what?
I was running fastJson 1.9.1
|
|
|
|

|
I have a class where a public property is null.
I set SerializeNullValues=false, and ToJSON() fails due to NullReferenceException.
Shouldn't the serializer simply ignore this null property? (Or maybe I don't understand how this setting is supposed to work.)
Here's the exception trace:
at fastJSON.JSONSerializer.WriteObject(Object obj) in C:\dev\myproj\trunk\proj\fastJSON\JsonSerializer.cs:line 242
at fastJSON.JSONSerializer.WriteValue(Object obj) in C:\dev\myproj\trunk\proj\fastJSON\JsonSerializer.cs:line 94
at fastJSON.JSONSerializer.WriteObject(Object obj) in C:\dev\myproj\trunk\proj\fastJSON\JsonSerializer.cs:line 256
at fastJSON.JSONSerializer.WriteValue(Object obj) in C:\dev\myproj\trunk\proj\fastJSON\JsonSerializer.cs:line 94
at fastJSON.JSONSerializer.ConvertToJSON(Object obj) in C:\dev\myproj\trunk\proj\fastJSON\JsonSerializer.cs:line 37
at fastJSON.JSON.ToJSON(Object obj, Boolean enableSerializerExtensions, Boolean enableFastGuid, Boolean enableOptimizedDatasetSchema, Boolean serializeNullValues) in C:\dev\myproj\trunk\proj\fastJSON\JSON.cs:line 58
at fastJSON.JSON.ToJSON(Object obj) in C:\dev\myproj\trunk\proj\fastJSON\JSON.cs:line 36
at proj.UserData.ToJSON() in C:\dev\myproj\trunk\proj\proj\UserData.cs:line 37
at proj.unit.test.UserDataTests.ToJSON() in C:\dev\myproj\trunk\proj\proj.unit.test\UserDataTests.cs:line 19
|
|
|
|

|
I pulled your latest release and got these two compile errors:
'System.Data.DataTable' does not contain a definition for 'ReadXmlSchema' and no extension method 'ReadXmlSchema' accepting a first argument of type 'System.Data.DataTable' could be found (are you missing a using directive or an assembly reference?)
C:\dev\MarketDelta-Footprint\trunk\Footprint\fastJSON\JSON.cs - line 823
'System.Data.DataTable' does not contain a definition for 'WriteXmlSchema' and no extension method 'WriteXmlSchema' accepting a first argument of type 'System.Data.DataTable' could be found (are you missing a using directive or an assembly reference?)
C:\dev\MarketDelta-Footprint\trunk\Footprint\fastJSON\JsonSerializer.cs - line 174
Can you assist?
Thanks.
|
|
|
|

|
Really good ... always improving ... finally you add support for public fields ... great ...
I will make some new comparisson test ...
Nice job ...
|
|
|
|

|
Hi, Mehdi:
Very good implementation. It is clean and small.
Does fastJSON support window phone platform?
If not, do you have plan to implement it in the near future?
Regards,
|
|
|
|

|
Excellent work. Now make it obtainable by nuget please
|
|
|
|

|
Hi!
I like fastJSON, i want write a custom javascriptConverter to convert every business objects to json, but Serialize function of JavaScriptConvert return a IDictionary(Of String, Object) and fastJSON return a json string?
Please give me a solution.
|
|
|
|
|

|
What a great article with superb detail! Thank you.
What approach would you recommend for implementing fastJSON in a MVC3/Silverlight setup?
I believe that if you create a nugget (www.nuget.org) fastJSON package; the adoption of fastJSON would skyrocket.
A "four-fecta" (a perfect scenario) could be MVC-REST/Silverlight/JSONP(callbacks)/fastJSON setup.
I am certain one could slam lots of data with mind-blowing speeds with fastJSON. I'm just concerned how easy a MVC/fastJSON(p) implementation could be.
Thoughts?
|
|
|
|

|
Excellent article!
Thanks for sharing.
|
|
|
|

|
I know you are busy with other stuff, but another thing for you to consider. TimeSpan serializes without value to:
{"$type":"System.TimeSpan, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"}
Not sure the best way to fix this?
|
|
|
|

|
Ok, never seen this error before
I'm doing .ToJson on an object as a result of a mvvmLight message being received...
{System.Security.VerificationException: Operation could destabilize the runtime.
at _(Object )
at fastJSON.JSONSerializer.WriteObject(Object obj)
at fastJSON.JSONSerializer.WriteValue(Object obj)
at fastJSON.JSONSerializer.WritePair(String name, Object value)
at fastJSON.JSONSerializer.WriteObject(Object obj)
at fastJSON.JSONSerializer.WriteValue(Object obj)
at fastJSON.JSONSerializer.WriteArray(IEnumerable array)
at fastJSON.JSONSerializer.WriteValue(Object obj)
at fastJSON.JSONSerializer.WritePair(String name, Object value)
at fastJSON.JSONSerializer.WriteObject(Object obj)
at fastJSON.JSONSerializer.WriteValue(Object obj)
at fastJSON.JSONSerializer.WriteArray(IEnumerable array)
at fastJSON.JSONSerializer.WriteValue(Object obj)
at fastJSON.JSONSerializer.WritePair(String name, Object value)
at fastJSON.JSONSerializer.WriteObject(Object obj)
at fastJSON.JSONSerializer.WriteValue(Object obj)
at fastJSON.JSONSerializer.ConvertToJSON(Object obj)
at fastJSON.JSON.ToJSON(Object obj, Boolean enableSerializerExtensions, Boolean enableFastGuid, Boolean enableOptimizedDatasetSchema, Boolean serializeNullValues)
at fastJSON.JSON.ToJSON(Object obj)
at Ultra.IsoDatabase.IsoDatabase.Save(Object obj, String key)
at vcpSL.ViewModel.CallCenterViewModel.Pulse(PulseMessage obj)
at GalaSoft.MvvmLight.Helpers.WeakAction`1.Execute(T parameter)
at GalaSoft.MvvmLight.Helpers.WeakAction`1.ExecuteWithObject(Object parameter)
at GalaSoft.MvvmLight.Messaging.Messenger.SendToList[TMessage](TMessage message, IEnumerable`1 list, Type messageTargetType, Object token)
at GalaSoft.MvvmLight.Messaging.Messenger.SendToTargetOrType[TMessage](TMessage message, Type messageTargetType, Object token)
at GalaSoft.MvvmLight.Messaging.Messenger.Send[TMessage](TMessage message)
at vcpSL.Messages.PulseMessage.Send()
at vcpSL.ViewModel.ApplicationSettings.<.ctor>b__0(Object s, EventArgs e)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)}
|
|
|
|

|
Hi there,
Been doing lots with the Sterling database
http://sterling.codeplex.com[^]
Could you have the same ability to decorate your class with ignore attributes of fields so they don't get serialised?
[JsonIgnore]
public string MyString {get;set;}
wouldn't get serialised for example
Many Thanks
Paul
|
|
|
|

|
Hi, folks
I have been testing with NETCF and mono Cecil but can't get them to work properly, I was hoping the win phone 7 would be as accomedating as silverlight 4 but it's not and has the same problems as netcf 3.5.
Any way I can release a version with slow reflection in the mean time until a work around is found, let me know what you think.
Cheers,
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
|
|
|
|

|
The subject says it all
Alberto Silva
|
|
|
|

|
When JSON is needed in my project I will give this a try - Great work.
|
|
|
|

|
Excellent and well-balanced article!
|
|
|
|

|
Fast and small, i�m using it in my framework.
http://lessframework.codeplex.com/documentation
Keep the good job.
|
|
|
|

|
Mehdi,
Many thanks for a great job on fastJSON!! Works great with generic classes. In the attached test program, ran into trouble when I attempted to deserialize a class which was derived from a generic class. Not a big deal really, since one can easily code around it. Just thought you might like to know...
In the attached C# code, if I add a member of type: class Telephones: List< Telephone >
to class: NameAndAddress and create a populated NameAndAddress instance, JSON.Instance.ToJSON() works OK. However,
the call to JSON.Instance.ToObject<NameAndAddress>() throws an exception:
at JSON.cs line 397 pi.setter(o,set);
Invalid Cast Exception was unhandled - unable to cast object of type 'System.Object[]' to type 'fastJSON.Telephones'.
Here's the code...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using fastJSON;
namespace fastJSonTest
{
public enum enumStates
{
es_Connecticut = 0x001,
es_Massachusetts = 0x002,
es_NewHampshire = 0x003
};
public enum enumTelephone
{
et_Undefined = 0x000,
et_Home = 0x001,
et_Work = 0x002,
et_Mobile = 0x003
};
public class Telephone
{
public enumTelephone Type { get; set; }
public string AreaCode { get; set; }
public string Exchange { get; set; }
public string Branch { get; set; }
public string Extension { get; set; }
public Telephone()
{
Type = 0x000;
}
public Telephone( enumTelephone et, string strAreaCode, string strExchange, string strBranch, string strExtension = null )
{
Type = et;
AreaCode = strAreaCode;
Exchange = strExchange;
Branch = strBranch;
Extension = strExtension;
}
};
public class NameAndAddress
{
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string Street { get; set; }
public string City { get; set; }
public enumStates State { get; set; }
public List< Telephone > Telephones { get; set; }
public string E_Mail { get; set; }
};
class Program
{
static void Main( string[] args )
{
List< Telephone > telephones = new List< Telephone >();
Telephone telephone = new Telephone( enumTelephone.et_Mobile,
"xxx",
"xxx",
"xxxx" );
telephones.Add( telephone );
telephone = new Telephone( enumTelephone.et_Work,
"yyy",
"yyy",
"yyyy" );
telephones.Add( telephone );
telephone = new Telephone( enumTelephone.et_Home,
"zzz",
"zzz",
"zzz" );
telephones.Add( telephone );
NameAndAddress nanda = new NameAndAddress();
nanda.FirstName = "aaaa";
nanda.MiddleName = "bbbb";
nanda.LastName = "cccc";
nanda.Street = "XX ... Street";
nanda.City = "DDDD";
nanda.State = enumStates.es_Massachusetts;
nanda.E_Mail = "...@...";
nanda.Telephones = telephones;
JSON.Instance.UseFastGuid = true;
JSON.Instance.UseOptimizedDatasetSchema = true;
JSON.Instance.UseSerializerExtension = true;
string strJSON = JSON.Instance.ToJSON( nanda );
Console.WriteLine( "Name and address in JSON format:" );
Console.WriteLine( "" );
Console.WriteLine( strJSON );
var varTemp = JSON.Instance.ToObject<NameAndAddress>( strJSON );
NameAndAddress nanda1 = varTemp as NameAndAddress;
if ( null != nanda1 )
{
Console.WriteLine( "Name and Address from JSON format:" );
Console.WriteLine( "" );
Console.WriteLine( nanda1.ToString() );
}
}
}
}
|
|
|
|

|
Hello,
Please forgive me for being a newbie. When i try to deserialize this JSON from bit.ly it hits me with a KeyNotFoundException in JSON.cs line 179.
{ "status_code": 200, "status_txt": "OK", "data": { "expand": [ { "short_url": "http:\/\/bit.ly\/ehnQdl", "long_url": "http:\/\/www.autogekocht.nl\/", "user_hash": "ehnQdl", "global_hash": "fQm50R" } ] } }
What am I doing wrong?
Many thanks in advance.
Stefan de Groot
Regards from the code junky
|
|
|
|

|
So far fastJSON is great! Thanks for the work so far. I have a newbie question I'm hoping someone can clear up. What's the best method for parsing JSON with mutiple objects in one string? I have a HTTP stream with multiple JSON objects coming in (ex {"id":"1"},{"id":"2"} and so on).
Right now I'm doing this:
var obj = fastJSON.JSON.Instance.ToObject<MessageClass>(response);
I am assuming this is where the special List<object[]> type mentioned above comes into play, but could you possibly provide a quick example of how to implement it?
Thanks!
|
|
|
|

|
I have to bring this up once more. I have done some more testing and the crash problem is new to 1.7.6 (it kinda work in 1.7.5 and 1.7, more below), because of the fast string, string dictionary handling. (As far as I can tell.)
Serializing and then deserializing a plain "new Exception("Something")", will crash in JSON.cs -> Getproperties(), since d.GenericTypes.Length == 0.
if(d.isDictionary && d.GenericTypes[0] == typeof(string) && d.GenericTypes[1]== typeof(string))
d.isStringDictionary = true;
I have uploaded a test project (VS2010) here: FastJsonConsoleTest.zip
So as an interim solution, so I don't get crashes I can go back to 1.7.5.
But while the earlier version does serialize the exception, it is pretty useless, since the only two properties serialized is HelpLink and Source. I would ofc. like .Message and .StackTrace as well, but these properties have CanWrite == false, so they are not serialized. (And couldn't be deserialized the standard way anyway.)
The only idea I have atm. for handling this, is to make a new base class for my exceptions that needs to be transfered, overwriting .Message and .StackTrace members. Don't know if you have a better idea to get something useful from Exceptions?
|
|
|
|

|
To test, try compile these belown:
string s = "{\"number1\":+0.01, \"number2\":.01}"
object o = jsonInstance.Parse(s);
To fix, update NextTokenCore() in JsonParser.cs whith these:
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case '-': case '+': case '.':
return Token.Number;
|
|
|
|

|
Till now the library only let public properties to be ser/deserialized but I think that:
public float celcius { get; private set; }
can be handled in a different way, if you try to serialize ther is not any progblem because de get is public but when trying to deserialize in throw an error due to setter process. In this particular case the exception can be by passed ... Normally when a class include that kind of properties they are setted internally because it depends of others internal values. This can be resolved just doing the property to become a public function but I think will be good that this lib take care of this situations).
What do you think?
Cheers,
JJ
|
|
|
|

|
Binary implementation of this library is to achieve even better results (I think), and smaller size results. If the size can be even smaller this could be an excellent tool for sockets connections (TCP send/receive ...) and abstract information (binary).
Of course, I changed some parts of my code (Binaryformmater) and I have obtained good reults ...
What do you think?
Cheers,
JJ
|
|
|
|

|
A helper function returns IEnumerable<ValidationResult>
When serialized with Json.NET, it returns
[{"MemberNames":["UserId"],"ErrorMessage":"UserId Z123456"}]
When tried fastJSON, it shows
{"$type":"System.Linq.Enumerable+WhereSelectEnumerableIterator`2[[System.ComponentModel.DataAnnotations.ValidationResult, System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35],[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"}
Any ideas? Thanks
modified on Thursday, April 14, 2011 12:37 PM
|
|
|
|

|
Are you planning to make more improvements to your library?
|
|
|
|

|
I was playing a little with your console test, and implementing binary for json.NET4.0 R1 ... and again your lib is faster ..., in fact in my tests json.NET serialize faster than binaryformatter but deserialize more slowly.
Unfortunatey, I couldn't make "exotic" text because json.NET threw an error ...
I will make some modifications in code in the console test because you serialize (again) and later deserialize in all "deserialize" functions. Usually the info will be already serialized .... (of course that will only reduce the time consumed by the function).
Writing the info to disk could be abother test ...
Once again excellent lib ... I like json.NET4 too but have some limitations and need to be improved for being faster.
Cheers.
JJ.
|
|
|
|

|
I want to know that is this library compatible with .Net Compact framework
|
|
|
|

|
If you serialize an array of T it tooks the properties of array insteads the properties of T.
class test
{
int a;
string b;
}
var c = new T[2];
JSON.ToJSON(c);
The function GetGetters return an empty array becuase no one of the prop. of array is writeable.
If a will found a fix i'll send you.
|
|
|
|

|
var b = JSON.Instance.ToObject(JSONCONTENT);
b is empty (no items parsed).
the json content is basically firefox 4 bookmark backup file, which you can find one in C:\Users\User\AppData\Roaming\Mozilla\Firefox\Profiles\[random folder name]\bookmarkbackups\
you may ignore the special characters found in the json content.
btw, the poco object must be public?
-------------------------------json content down here-----------------------------
{"title":"","id":1,"dateAdded":1301645281528000,"lastModified":1301823230784000,"type":"text/x-moz-place-container","root":"placesRoot","children":[{"title":"书签菜单","id":2,"parent":1,"dateAdded":1301645281529000,"lastModified":1301645281925000,"type":"text/x-moz-place-container","root":"bookmarksMenuFolder","children":[{"title":"最近使用的书签","id":14,"parent":2,"annos":[{"name":"Places/SmartBookmark","flags":0,"expires":4,"mimeType":null,"type":3,"value":"RecentlyBookmarked"}],"type":"text/x-moz-place","uri":"place:folder=BOOKMARKS_MENU&folder=UNFILED_BOOKMARKS&folder=TOOLBAR&sort=12&excludeQueries=1&excludeItemIfParentHasAnnotation=livemark%2FfeedURI&maxResults=10&queryType=1"},{"index":1,"title":"最近使用的标签","id":15,"parent":2,"annos":[{"name":"Places/SmartBookmark","flags":0,"expires":4,"mimeType":null,"type":3,"value":"RecentTags"}],"type":"text/x-moz-place","uri":"place:sort=14&type=6&maxResults=10&queryType=1"},{"index":2,"title":"","id":16,"parent":2,"dateAdded":1301645281925000,"lastModified":1301645281925000,"type":"text/x-moz-place-separator"},{"index":3,"title":"Mozilla Firefox","id":8,"parent":2,"dateAdded":1301645281852000,"lastModified":1301645281855000,"type":"text/x-moz-place-container","children":[{"title":"帮助和教程","id":9,"parent":8,"dateAdded":1301645281852000,"lastModified":1301645281853000,"type":"text/x-moz-place","uri":"http://www.mozilla.com/zh-CN/firefox/help/"},{"index":1,"title":"自定义 Firefox","id":10,"parent":8,"dateAdded":1301645281853000,"lastModified":1301645281854000,"type":"text/x-moz-place","uri":"http://www.mozilla.com/zh-CN/firefox/customize/"},{"index":2,"title":"加入进来","id":11,"parent":8,"dateAdded":1301645281854000,"lastModified":1301645281855000,"type":"text/x-moz-place","uri":"http://www.mozilla.com/zh-CN/firefox/community/"},{"index":3,"title":"关于我们","id":12,"parent":8,"dateAdded":1301645281855000,"lastModified":1301645281856000,"type":"text/x-moz-place","uri":"http://www.mozilla.com/zh-CN/about/"}]}]},{"index":1,"title":"书签工具栏","id":3,"parent":1,"dateAdded":1301645281529000,"lastModified":1301823253028000,"annos":[{"name":"bookmarkProperties/description","flags":0,"expires":4,"mimeType":null,"type":3,"value":"添加到此文件夹的书签会被显示到书签工具栏中"}],"type":"text/x-moz-place-container","root":"toolbarFolder","children":[{"title":"火狐官方站点","id":17,"parent":3,"dateAdded":1301645282022000,"lastModified":1301645282142000,"type":"text/x-moz-place-container","children":[{"title":"火狐社区","id":18,"parent":17,"dateAdded":1301645282033000,"lastModified":1301645282033000,"type":"text/x-moz-place","uri":"http://mozilla.com.cn/?src=ffbookmark"},{"index":1,"title":"火狐DIY","id":19,"parent":17,"dateAdded":1301645282067000,"lastModified":1301645282067000,"type":"text/x-moz-place","uri":"http://diy.mozilla.com.cn/?src=ffbookmark"},{"index":2,"title":"火狐扩展精选","id":20,"parent":17,"dateAdded":1301645282100000,"lastModified":1301645282100000,"type":"text/x-moz-place","uri":"http://mozilla.com.cn/selections/?src=ffbookmark"},{"index":3,"title":"火狐商店","id":21,"parent":17,"dateAdded":1301645282101000,"lastModified":1301645282101000,"type":"text/x-moz-place","uri":"http://firefox001.taobao.com/"},{"index":4,"title":"谋智网络官方网站","id":22,"parent":17,"dateAdded":1301645282142000,"lastModified":1301645282142000,"type":"text/x-moz-place","uri":"http://www.firefox.com.cn/"}]},{"index":1,"title":"访问最多","id":13,"parent":3,"annos":[{"name":"Places/SmartBookmark","flags":0,"expires":4,"mimeType":null,"type":3,"value":"MostVisited"}],"type":"text/x-moz-place","uri":"place:sort=8&redirectsMode=2&maxResults=10"},{"index":2,"title":"新手上路","id":6,"parent":3,"dateAdded":1301645281850000,"lastModified":1301645281851000,"type":"text/x-moz-place","uri":"http://www.mozilla.com/zh-CN/firefox/central/"},{"index":3,"title":"最新头条","id":7,"parent":3,"dateAdded":1301645281851000,"lastModified":1301823209654000,"livemark":1,"annos":[{"name":"placesInternal/READ_ONLY","flags":0,"expires":4,"mimeType":null,"type":1,"value":1},{"name":"livemark/feedURI","flags":0,"expires":4,"mimeType":null,"type":3,"value":"http://fxfeeds.mozilla.com/zh-CN/firefox/headlines.xml"},{"name":"livemark/siteURI","flags":0,"expires":4,"mimeType":null,"type":3,"value":"http://roll.news.sina.com.cn/s/"},{"name":"livemark/expiration","flags":0,"expires":4,"mimeType":null,"type":2,"value":1301826809654}],"type":"text/x-moz-place-container","children":[]},{"index":4,"title":"网址大全","id":23,"parent":3,"dateAdded":1301645282187000,"lastModified":1301645282222000,"annos":[{"name":"bookmarkProperties/description","flags":0,"expires":4,"mimeType":null,"type":3,"value":"火狐网址大全"}],"type":"text/x-moz-place","uri":"http://www.huohu123.com/?src=ffbookmark"},{"index":5,"title":"智能实验室","id":42,"parent":3,"dateAdded":1301645344543000,"lastModified":1301645344543000,"type":"text/x-moz-place","uri":"http://www.xnlab.com/zh/default.htm","charset":"GB2312"},{"index":6,"title":"cnBeta.COM_网友媒体与言论平台","id":68,"parent":3,"dateAdded":1301823253028000,"lastModified":1301823253028000,"type":"text/x-moz-place","uri":"http://www.cnbeta.com/","charset":"GB2312"}]},{"index":2,"title":"标签","id":4,"parent":1,"dateAdded":1301645281529000,"lastModified":1301645281530000,"type":"text/x-moz-place-container","root":"tagsFolder","children":[]},{"index":3,"title":"未分类书签","id":5,"parent":1,"dateAdded":1301645281530000,"lastModified":1301823246860000,"type":"text/x-moz-place-container","root":"unfiledBookmarksFolder","children":[{"title":"智能实验室","id":41,"parent":5,"dateAdded":1301645325248000,"lastModified":1301645325284000,"type":"text/x-moz-place","uri":"http://www.xnlab.com/zh/default.htm","charset":"GB2312"},{"index":1,"title":"cnBeta.COM_网友媒体与言论平台","id":67,"parent":5,"dateAdded":1301823246860000,"lastModified":1301823246878000,"annos":[{"name":"bookmarkProperties/description","flags":0,"expires":4,"mimeType":null,"type":3,"value":"cnBeta.com为您提供最新最快IT业界资讯,报导立场公正中立,网友讨论气氛浓厚.创造出最适合目标人群阅读的新闻、评论、观点和专访"}],"type":"text/x-moz-place","uri":"http://www.cnbeta.com/","charset":"GB2312"}]}]}
Regards,
unruledboy_at_gmail_dot_com
http://www.xnlab.com
|
|
|
|

|
I tried to send a message containing an exception. My struct sent looks something like:
public class {
[DataMember]
public object Data { get; set; }
[DataMember]
public String Message { get; set; }
}
Where Data is an Exception object. In this specific case it is an EndpointNotFoundException, haven't tested with other Exception types though, but I assume it's the same?
Deserializing it gives an IndexOutOfRange Exception, with the following relevant stack trace:
at fastJSON.JSON.Getproperties(Type type, String typename) in [...]\fastJSON\JSON.cs:linje 197
at fastJSON.JSON.ParseDictionary(Dictionary`2 d, Type type) in [...]\fastJSON\JSON.cs:linje 327
at fastJSON.JSON.ParseDictionary(Dictionary`2 d, Type type) in [...]\fastJSON\JSON.cs:linje 386
at fastJSON.JSON.ToObject(String json, Type type) in [...]\fastJSON\JSON.cs:linje 72
at fastJSON.JSON.ToObject(String json) in [...]\fastJSON\JSON.cs:linje 64
The line throwing the exception is:
if(d.isDictionary && d.GenericTypes[0] == typeof(string) && d.GenericTypes[1]== typeof(string))
Have you tried serializing/deserializing an exception or am I too ambitious? (I guess I could just send the ex.Message and I might do that anyway, since it might not be a good idea sending the whole exception object for security reasons.)
|
|
|
|

|
I try to serialize an object and get this exception when fastJson invokes p.Getter(obj) in WriteObject(): the type which is not supported is
public struct TIME_ZONE_INFORMATION
{
...
public string DisplayName { get; set; }
}
Is it related to the struct? Do you have a workaround ?
Thx
|
|
|
|

|
What do you mean by saying it dynamically creates types?
Are you saying that just like in javascript, it will create a type from the json that is useable in c# without an existing class?
Or are you saying it will create an instance of an existing type?
BTW, after reading this article, I looked at a couple of your other articles, and I'm impressed with your work, I'm giving you a 5 here.
|
|
|
|

|
Have you considered putting the source code on GitHub, CodePlex, or something like that? It would make it much easier to accept contributions from people.
Thanks.
Slava
|
|
|
|

|
In a class I'm serializing, I have a System.Drawing.Color property. As you might know, this type does not serialize well, so I have this workaround. (Doing the same on my Webservice on XML.)
[DataMember]
public Int32 ColorARGB
{
get { return this.Color.ToArgb(); }
set { this.Color = System.Drawing.Color.FromArgb(value); }
}
public System.Drawing.Color Color { get; set; }
I only want the ColorARGB property to get serialized, but I can't figure out how to do this with fastJSON, so both Color and ColorARGB is serialized. Looking at the WriteObject code, it doesn't look like it checks for any serialization attributes etc.? Any easy way around this? (Besides ofc. making a special case in WriteValue() to handle System.Drawing.Color)
|
|
|
|
|

|
Hi,
does FastJSON support array like "JsonArray" in JSON.NET?
In JSON.NET, it has something called JToken, which can cache the parsed json object, then use TryGetValue to get a single value or JsonArray to get a list of values.
Regards,
unruledboy_at_gmail_dot_com
http://www.xnlab.com
|
|
|
|

|
Nice work!
a small comment:
line 102 IMHO should read:
_output.Append(dateTime.Year.ToString("0000", NumberFormatInfo.InvariantInfo));
(added "0000")
Otherwise DateTime.MinValue gets serialized as "1-..." instead of "0001-" leading to an uncaught exception on deserializing.
Cheers
Phil
|
|
|
|

|
Hello All,
Please post your performance results with the machine you tested on here.
Thanks,
Its the man, not the machine - Chuck Yeager
|
|
|
|

|
I found out that doctionaries are persisted like this:
[{"k":"SomeKey","v":"SomeValue"}]
Shouldn't it be like this?:
[{"SomeKey":"SomeValue"}]
Or is the k/v approach standard for dictionaries?
|
|
|
|

|
Till now I have changed many parts of the code from one project where I used BinaryFormatter, now I have only one thing two change (and I sue a lot) multi dimensional arrays, for the way how the project had been created is really complicated to use another technique different to multi arrays.
I can see that you're improving your lib really fast, so I was wondering if you're thinking to release soon a version that can ser/deserialize multi arrays?
Thanks ... and keep the good work ...
|
|
|
|

|
Hi, nice implementation. I'm looking for the fastest json parser around. I have two questions though.
1. Is it possible to have optional properties? Some sort of attribute if a value is null, don't serialize it. (I modded the code to check for null values)
2. What if i serialize between different systems where the other system does not use fastJSON; I don't want to be dependent on the $type attribute to be able to deserialize. Is it possible to for instance use generics to tell fastJSON which type to deserialize to?
Those two features are crucial for me,
Best Regards
Patrik
|
|
|
|

|
Superb article! I especially liked the Pro/Con section and the neat performance dissection. A well written article, thanks!
|
|
|
|

|
This is something very, very useful to any web dev, be it junior or senior. Well done, sir.
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
Smallest, fastest polymorphic JSON serializer (with Silverlight4 and MonoDroid support)
| Type | Article |
| Licence | CPOL |
| First Posted | 19 Feb 2011 |
| Views | 1,599,112 |
| Downloads | 26,638 |
| Bookmarked | 467 times |
|
|