Forum Xamarin.Android


May I please have some advice on how to use GSON to pass an object to a different activity in Xamarin?


  • SKallSKall USMember ✭✭✭✭

    Use Json.NET or ServiceStack.Text instead. If it is a large object the latter is better as it is much faster.

    Use the serialize function to convert the object to string and on the activity use deserialize to convert back into object.


    var str = ServiceStack.Text.JsonSerializer.SerializeToString(obj);
    T obj = ServiceStack.Text.JsonSerializer.DeserializeFromString<T>(str);


    var str = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
    T obj = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(str);
Sign In or Register to comment.