0

I am working on windows phone 8 app. In which I need to call an api to get some response, that I am serializing and saving into local settings While saving these data I am getting an exception of type 'System.Runtime.Serialization.SerializationException'.

My Code is,

    string someData = responseDataDict["SomeData"].ToString();
    if someData != null) 
    {
       Dictionary<string, Object> someDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(someData);
       Datastore.SaveData = stringDict; 
    }

    public static Datastore
    {
       get
       {
          if (localSettings.Contains("SaveData"))
          {
             return (Dictionary<string, Object>)localSettings["SaveData];
             else
             return null;
          }
      }
      set
      {
          localSettings["SaveData"] = value; 
          localSettings.Save();
      }
 }

}

The response from api is,

"MESSAGE": "Some Message",
"UI_MESSAGE": {
    "LEFT": "OK",
    "RIGHT": "CANCEL",        
 }

I think the problem is in "UI_MESSAGE",

The Exception is,

System.Runtime.Serialization.SerializationException: Type 'Newtonsoft.Json.Linq.JObject' with data contract name 'ArrayOfKeyValueOfstringJTokeneJCYCtcq:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

Please help me to resolve this issue, Thanks in advance

1 Answers1

0

You can't (easily) serialize the data because the serializer doesn't know how to serialize Newtonsoft.Json.Linq.JObject types.

We could try to figure out how to get the serializer working with this type, which may or may not take lots of time, or we could stop and think for a bit...

You grab the response data in the line

string someData = responseDataDict["SomeData"].ToString();

What is someData? It's

{
"MESSAGE": "Some Message",
"UI_MESSAGE": {
    "LEFT": "OK",
    "RIGHT": "CANCEL",        
}

That's a json string. A serialized javascript object. It's already bloody serialized.

Save that in localSettings.