1

Closed

JSON serialize/deserialize not working with mono develop

description

Hello,
 

I am new to Monotouch/iOS development. I using

MonoDevelop 2.8.8.4
Installation UUID: 0d3db625-7df9-4282-9aa6-177c25a46d07
Runtime:
    Mono 2.10.9 (tarball Tue Mar 20 15:31:37 EDT 2012) 
    GTK 2.24.10 
    GTK# (2.12.0.0) 
Mono for Android not installed
Apple Developer Tools:
     Xcode 4.2.1 (834) 
     Build 4D502 
Monotouch: 5.2.10 (Evaluation)

 

 
I am trying to serialize object to json string using Newtonsoft 3.5.
 
Very simple code but not working.. Can anybody can please help me ...
 
          partial void Action_Clicked (MonoTouch.Foundation.NSObject sender) 
          { 
                    myDTO test = new myDTO(); 
                    string teststring = ObjToJSON(test); 
            } 
 
    public string ObjToJSON(myDTO oObject)   //Old function name is ObjToJSON_WithWrapper 
    { 
                    string sJSON = ""; 
                    sJSON = Newtonsoft.Json.JsonConvert.SerializeObject(oObject); 
                    return sJSON; 
    } 

    public  myDTO JSONToObj(String JSONString) //Old function name is JSONToObjNew 
    { 
                    myDTO deseri =  JsonConvert.DeserializeObject<myDTO>(JSONString); 
                return deseri; 
    } 
 
 
 
    public class myDTO 
    { 
            public myDTO() 
            { 
            } 

            public string StringObject {get; set;} 
    } 
 
 
 
Above is my simple test code but it's giving me error when it's run Newtonsoft.Json.JsonConvert.SerializeObject(oObject);
 
*** ERROR***
 
{System.TypeLoadException: A type load exception has occurred. at Newtonsoft.Json.Utilities.ThreadSafeStore2[System.Type,System.Type].AddValue (System.Type key) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Utilities.ThreadSafeStore2[System.Type,System.Type].Get (System.Type key) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.JsonTypeReflector.GetAssociatedMetadataType (System.Type type) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute[JsonContainerAttribute] (System.Type type) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute[JsonContainerAttribute] (ICustomAttributeProvider attributeProvider) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Utilities.ThreadSafeStore2[System.Reflection.ICustomAttributeProvider,Newtonsoft.Json.JsonContainerAttribute].AddValue (ICustomAttributeProvider key) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Utilities.ThreadSafeStore2[System.Reflection.ICustomAttributeProvider,Newtonsoft.Json.JsonContainerAttribute].Get (ICustomAttributeProvider key) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.CachedAttributeGetter`1[Newtonsoft.Json.JsonContainerAttribute].GetAttribute (ICustomAttributeProvider type) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.JsonTypeReflector.GetJsonContainerAttribute (System.Type type) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.JsonTypeReflector.GetJsonObjectAttribute (System.Type type) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System.Type objectType) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System.Type type) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContractSafe (System.Object value) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.JsonSerializer.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, Formatting formatting, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value) [0x00000] in <filename unknown>:0 at JSONTest1.JSONTest1ViewController.ObjToJSON (JSONTest1.myDTO oObject) [0x00006] in /Users/developer/Projects/JSONTest1/JSONTest1/JSONTest1ViewController.cs:61 at JSONTest1.JSONTest1ViewController.Action_Clicked (MonoTouch.Foundation.NSObject sender) [0x00006] in /Users/developer/Projects/JSONTest1/JSONTest1/JSONTest1ViewController.cs:52 at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr) at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29 at JSONTest1.Application.Main (System.String[] args) [0x00000] in /Users/developer/Projects/JSONTest1/JSONTest1/Main.cs:17 }
Closed Apr 13, 2012 at 12:13 AM by JamesNK
I don't have MonoTouch. You'll have to ask them to help you.

comments