am trying to pass value using Newtonsoft.Json from shared project to droid project. So in my shared project i am serializing the object as follows and getting certain result, also displayed below. Then i am taking that result to droid project and trying to deserialize value however i am getting an exception also displayed below
i am trying to pass value using Newtonsoft.Json from shared project to droid project. So in my shared project i am serializing the object as follows and getting certain result, also displayed below. Then i am taking that result to droid project and trying to deserialize value however i am getting an exception also displayed below
My Project
public void PushDictionary(List allWordsOfUserForAutomat)
{
var second = new Intent(MainActivity.Instance, typeof(LockScreenDictionary));
second.PutExtra("MyData", JsonConvert.SerializeObject(allWordsOfUserForAutomat));
var result = JsonConvert.SerializeObject(allWordsOfUserForAutomat);
Console.WriteLine(result);
MainActivity.Instance.StartActivity(second);
}
Outcome of my result from json here is "[{\"Id\":3391,\"SentenceId\":40616,\"TextEng\":\"expensive\",\"Explanation\":\"expensive (price)\",\"GrammarDetail\":null,\"DateToShow\":\"0001-01-01T00:00:00\"}]"
My droid
var allWordsOfUserForAutomat = JsonConvert.DeserializeObject(Intent.GetStringExtra("MyData"));
List _allWordsOfUserForAutomat = null;
_allWordsOfUserForAutomat.Add(allWordsOfUserForAutomat);
LangUpDictionaryPlayer.PlayAutomat(_allWordsOfUserForAutomat);
However i am getting this exception, can someone please advise me
Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'AT.Model.Word' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.