问题
I need to Serialize and De-serialize Custom Objects under .NET Compact Framework 2.0. I have gone through JSON.NET 3.5 but it need .NET Compact Framework 3.5.
I am restricted to not to upgrade from 2.0 to 3.5. When I am trying with version JSON.Net 2.0, Serialize and Deserialize operations are hanging up.
---Serialize-----
List<string> strMessage = (JavaScriptConvert.DeserializeObject(results, typeof(List<string>)) as List<string>);
-----Deserialize----
List<object> paramObject = new List<object>(paramCollection);
string postData = string.Empty;
if (paramObject.Count > 0)
{
postData = JavaScriptConvert.SerializeObject(paramObject);
}
Note: paramCollection is the Array of objects ( object[] )
Is there something wrong in the above code? The same I tested with Desktop and I found it working but not in Compact Framework.
回答1:
about a year ago I faced the same sort of issue. JSON, compact framework, .net 2
I ended up using http://jsoncf.codeplex.com/
The source page I found on codebetter.com does contain this disclaimer:
Use it at your own risk - it’s very early in in development and poorly tested.
On the whole I found it works; From memory it does not deal with nulls nicely, and I think I had to tweak datetime serialisation to make it work the way other json serialisers do.
If you're interested in pursuing this I can go and find the amendments I needed to make and post them.
Andrew
来源:https://stackoverflow.com/questions/8831085/json-serializer-for-net-compactframework-2-0