这是我在客户端的代码:
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;}
但我在这一行上收到错误:
var jObj2 = (IEnumerable<Model.Print>)JsonConvert.DeserializeObject(strjson);
错误是:
'Newtonsoft.Json.linq.JArray' to type 'System.Collections.Generic.IEnumerable`1[InformeDWorkerServer.Model.Print]'.
strjson包含一个值:
[ {"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","CompanyRef":"00000000-0000-0000-0000-000000000000"}]
我错过了什么?
解决方法 使用JsonConvert.DeserializeObject< T>代替:var jObj2 = JsonConvert.DeserializeObject<List<Model.Print>>(strjson);总结
以上是内存溢出为你收集整理的c# – Newtonsoft.Json.Linq.JArray’输入’System.Collections.Generic.IEnumerable全部内容,希望文章能够帮你解决c# – Newtonsoft.Json.Linq.JArray’输入’System.Collections.Generic.IEnumerable所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)