I\'m getting some very weird behaviour in my Xamarin.Forms Project.
I\'m retrieving some serialized data from a REST API. I\'m then trying to use Json.NET to deseri
Possible Causes
Thanks a lot to all the responses so far! Sadly none of them worked for me.
After a lot of trial and error I found that I am able to access my data like so:
var blub = JsonConvert.DeserializeObject(booksString);
foreach (var element in (JArray)blub)
{
var blublub = ((JObject)element).SelectToken("$.Title").ToString();
}
But it would be an absolute pain if I had to implement my whole API this way... Are there any other ideas from you guys?
Please try like this:
Item item = JObject.Parse (json).ToObject<Item> ();
Yes, it's kind of ugly fix, but if it's working, it's working :)
Just got back to this problem. In case anyone‘s wondering: Turns out the Xamarin Live Player I’ve recently had to use has some problems with Json.NET. (https://developer.xamarin.com/guides/cross-platform/live/limitations/)
I knew it had to be something stupid... Well maybe I can save someone else some time!
Setting iOS Build Linker Behavior to "Link Framework SDKs only" fixed this for me.
As T.J.Purtell.1752 describes in the referenced xamarin thread, the Xamarin Linker will strip out unused types, methods, and fields.
Link Framework SDKs only prevents that happening for my application classes, which is fine in my conmtext.
Based on the JSON being returned it would need to be desrialized to an array where the objects map for example
public class Isbn {
public string Isbn10 { get; set; }
public string Isbn13 { get; set; }
}
public class Item {
public Isbn Isbn { get; set; }
public string Title { get; set; }
public IList<string> Authors { get; set; }
public string Publisher { get; set; }
public string ReleaseDate { get; set; }
public int PageCount { get; set; }
public string Description { get; set; }
public string ThumbnailUrl { get; set; }
}
And then deserialized like
var items = JsonConvert.DeserializeObject<Item[]>(json);