I am working on a sandbox solution in Sharepoint, important limitations (regarding this issue) due to this is the use of .net 3.5, and there are no reflections.
EXAMPLE 1
If I try to deserialize as a JSON string into a simple class like this, it works fine:
JSON STRING
{"field":"Picture1","url":"whatever"}
C # CLASS
public class PictureSetting { public string field { get; set; } public string url { get; set; } }
EXAMPLE 2
But if I try to deserialize a slightly more complex string, I get an error message:
JSON STRING
{ "Rows": [ { "Columns": [ { "Width": "100" } ] } ] }
C # Classes
internal class PageStructure { public List<StructureElement> Rows { get; set; } public PageStructure() { Rows = new List<StructureElement>(); } } internal class StructureElement { public List<BlockAssigment> Columns { get; set; } public StructureElement() { Columns = new List<BlockAssigment>(); } } internal class BlockAssigment { public string Width { get; set; } }
ERROR
A permission request of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089' failed.
* deserialization
The code I use to deserialize both examples is simply the standard .net:
var serializer = new JavaScriptSerializer(); var obj = serializer.Deserialize<PageStructure>("jsonstring");
So, for the first example, it seems .net does not use reflection, because it works. So the question is:
Is there a way to deserialize the second example without using .net with internal reflection?
Changing both JSON strings and C # classes is not a problem, I just have to save the structure (the base object with strings, including columns) in some way.