我需要返回一个json对象,但是我得到了以下错误:
错误1不能隐式地将类型'Newtonsoft.Json.Linq.JObject‘转换为Newtonsoft.Json.Linq.JObject存在显式转换(是否缺少强制转换?)
有人能帮我解决这个错误吗?
public static IEnumerable<JObject> GetListOfHotels() const string dataPath = "https://api.eancdn.com/ean-services/rs/hotel/v3/list?minorRev=99&cid=55505&apiKey=key&customerUserAgent=Google&customerIpAddress=123.456&locale=en_US¤cyCode=USD&destinationString=washington,united+kingdom&supplierCacheTolerance=MED&arrivalDate=12/12/2013&departureDate=12/15/2013&room1=2&mberOfResults=1&supplierCacheTolerance=MED_ENHANCED"; var request = WebRequest.Create(dataPath); request.Method = "POST"; const string postData = dataPath; var byteArray = Encoding.UTF8.GetBytes(postData); request.ContentType = "application/json"; request.ContentLength = byteArray.Length; var dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); var response = request.GetResponse(); var responseCode = (((HttpWebResponse) response).StatusDescription); var responseStream = response.GetResponseStream(); var responseReader = new StreamReader(responseStream, Encoding.UTF8); var responseString = responseReader.ReadToEnd(); var root = JObject.Parse(responseString); return root; }
发布于 2013-08-04 06:49:05
在使用Ext.Direct客户端代理从Sencha ExtJS 4数据存储区调用.NET服务器端堆栈时,我也有相同的异常。此服务器端堆栈引用Newtonsoft.Json.dll .NET程序集(.NET 4.0)。当我的Ext.Direct存储区抛出此异常时,它正在存储中的分类器和石斑鱼属性中传递嵌套对象。我通过在花括号周围加上方括号来修正它。如果您想知道原因,可以在这里下载框架: https://code.google.com/p/extdirect4dotnet/ 。
旧 (抛出异常):
Ext.define('MyApp.store.Hierarchy', { extend : 'Ext.data.Store', model : 'R.model.Hierarchy', sorters: { property: 'namespace_id', direction: 'ASC' remoteSort: true, groupers: { property: 'namespace_id', direction: 'ASC' remoteGroup: true, proxy: { type: 'direct', directFn: Tree_CRUD.read, reader: { root: 'data' });
New (用括号修正):
Ext.define('MyApp.store.Hierarchy', { extend : 'Ext.data.Store', model : 'R.model.Hierarchy', sorters: [{ property: 'namespace_id', direction: 'ASC' remoteSort: true, groupers: [{ property: 'namespace_id', direction: 'ASC' remoteGroup: true,3 proxy: { type: 'direct',