c# - Newtonsoft.Json.Linq.JArray' to type 'System.Collections.Generic.IEnumerable -
i calling web api c# desktop client.
this code on client:
public ienumerable<model.print> get() { var print = new list<model.print>(); using (var client = new httpclient()) { client.baseaddress = new uri(shared.url); client.defaultrequestheaders.accept.clear(); client.defaultrequestheaders.accept.add(new mediatypewithqualityheadervalue(shared.headertype)); var response = client.getasync(route + "?" + generaltags.customer_ref + "=" + new guid().tostring()).result; if (response.issuccessstatuscode) { string strjson = response.content.readasstringasync().result; var jobj2 = (ienumerable<model.print>)jsonconvert.deserializeobject(strjson); } else { everror(new exception(string.format("{0}: {1}", (int)response.statuscode, response.reasonphrase)), errortags.print_get); } } return print; }
but error on line:
var jobj2 = (ienumerable<model.print>)jsonconvert.deserializeobject(strjson);
the error is:
'newtonsoft.json.linq.jarray' type 'system.collections.generic.ienumerable`1[informedworkerserver.model.print]'.
the strjson contains value:
[ {"printid":1,"printref":"00000000-0000-0000-0000-000000000000","header":"header","tc":"tc","companyref":"00000000-0000-0000-0000-000000000000"}, {"printid":2,"printref":"39a10cee-7cb3-4ed3-aec2-293761eed96d","header":"header","tc":"tc","companyref":"00000000-0000-0000-0000-000000000000"}]
what missing?
use jsonconvert.deserializeobject<t>
instead:
var jobj2 = jsonconvert.deserializeobject<list<model.print>>(strjson);
Comments
Post a Comment